Question

I am running a python script to load some data into db2 database. Yet, I came up with the following module-loading error:

Traceback (most recent call last):
  File "myscript.py", line 22, in ?
    import DB2
  File "/opt/freeware/lib/python2.3/site-packages/DB2.py", line 12, in ?
    import _db2
ImportError: Could not load module /opt/freeware/lib/python2.3/site-packages/_db2.so.
   Dependent module libdb2.a(shr.o) could not be loaded.
Could not load module libdb2.a(shr.o).
System error: No such file or directory
Could not load module /opt/freeware/lib/python2.3/site-packages/_db2.so.
   Dependent module /opt/freeware/lib/python2.3/site-packages/_db2.so could not be loaded.

Here is my python module directory:

[dbadmin@bldr2:/opt/freeware/lib/python2.3/site-packages]# ls -l
total 800
-rw-r--r--    1 root     system         8142 May 30 2008  DB2.py
-rw-r--r--    1 root     system        17133 May 30 2008  DB2.pyc
-rw-r--r--    1 root     system          119 Aug 09 2005  README
-rwxr-xr-x    1 root     system        66550 May 30 2008  _db2.so
drwxr-xr-x    2 root     system          256 Mar 31 2009  logging
-rw-r--r--    1 root     system       307200 Jan 13 15:19 python-modules.tar

What could be wrong here? And what the fix would be?

Update: I re-ran the command manually, and it succeeds without spitting errors. Yet, the job was originally a crontab entry, like:

18 * * * * myscript.py [parameter_list] >cron_nag.log 2>&1

The log I pasted out at the top was in this "cron_nag.log". But when I re-ran the command manually, the error was cleared, no more complaining of module-loading, and everything is smooth.

Why the difference between crontab entry and the manual run? I used the same user dbadmin to run the command manually as the crontab entry does. They should produce the same content in the log file, shouldn't they?

Was it helpful?

Solution

Try to force to load the db2 profile. Suppose the instance is at db2inst1

 18 * * * * . ~db2inst1/sqllib/db2profile ; myscript.py [parameter_list] >cron_nag.log 2>&1

The problem is that the cron does not load your .profile, and the db2profile is loaded from the .profile.

Also, if you create another shell, that new shell could not keep the db2profile or the connection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top