开发者

How do I get ibm_db or PyDB2 python modules to work with DB2 in Mac OS X 10.7 Lion?

开发者 https://www.devze.com 2023-03-28 03:17 出处:网络
I used this question/answer to install DB2 in Lion: How do I install IBM DB2 Express-C on Mac OS X 10.7 Lion?

I used this question/answer to install DB2 in Lion: How do I install IBM DB2 Express-C on Mac OS X 10.7 Lion?

After configuring my databases, I am able to use db2 from the command line to execute queries, but the python modules ibm_db and PyDB2 both fail to import with the following error:

>>> import ibm_db
Traceback (most recent call last):
 File "<stdin>", line 1, 开发者_运维问答in <module>
ImportError: dlopen(/Library/Python/2.7/site-packages/ibm_db-1.0.4-py2.7-macosx-10.7-intel.egg/ibm_db.so, 2): Symbol not found: _dsIsDirServiceRunning
 Referenced from: /Users/<username>/sqllib/lib64/libdb2.dylib
 Expected in: /System/Library/Frameworks/DirectoryService.framework/Versions/A/DirectoryService

How can I fix this and get ibm_db and PyDB2 to work properly with DB2 in Lion?

edit: moved answer to answers


Answer:

The problem is that a particular symbol in the DirectoryService framework was finally removed in Lion (it was deprecated in 10.2). libdb2.dylib, which is installed by DB2 Express-C attempts to call this function, and causes the error when importing either python module.

To work around this, you need to configure your environment to link against an older version of the DirectoryService framework. To do this, you will need an installation of Snow Leopard (it may work with older versions, but I have not tested it, and you will want the newest you can get your hands on, that isn't Lion, of course). You will find the DirectoryService framework installed here:

/System/Library/Frameworks/DirectoryService.framework/

Copy that directory from a Snow Leopard installation to any location you want in your Lion installation. For this example, I copied the DirectoryService.framework directory into a directory named OldFrameworks in ~ :

~/OldFrameworks/DirectoryService.framework/

Set the environment variable $DYLD_LIBRARY_PATH to contain the path to the actual library:

export DYLD_LIBRARY_PATH=${HOME}/OldFrameworks/DirectoryService.framework/Versions/Current/:${DYLD_LIBRARY_PATH}

Any environment in which you perform the above command will be configured to allow python to import ibm_db or PyDB2. Add it to your .profile, .bashrc, etc. to permanently configure your environment. Remember, though, this means all commands executed in the configured environment will attempt to link against the snow leopard version of DirectoryService. This could potentially cause errors with other tools (I have yet to encounter any). It would be prudent to only set DYLD_LIBRARY_PATH in shells where you need it.


You can change the db2 libraries using install_name_tool to look at the copied version of DirectoryService.framework, so you don't have to change DYLD_LIBRARY_PATH

Full credit goes to the following, I am simply updating this thread having been through the process of install db2 / ibm_db on Lion and finding this thread as one of the top hits via Google.

http://www.ibm.com/developerworks/forums/thread.jspa?threadID=238136&start=30&tstart=0

with other options described here:

http://www.ibm.com/developerworks/forums/message.jspa?messageID=14604855#14604855

The answer (should the above thread disappear):

Copy the Snow Leopard DirectoryService.framework to

/opt/SL_Frameworks/DirectoryService.framework 

Then

cd /opt/IBM/db2/V9.5/
install_name_tool -change /System/Library/Frameworks/DirectoryService.framework/Versions/A/DirectoryService /opt/SL_Frameworks/DirectoryService.framework/Versions/A/DirectoryService lib64/libdb2sec.dylib
install_name_tool -change /System/Library/Frameworks/DirectoryService.framework/Versions/A/DirectoryService /opt/SL_Frameworks/DirectoryService.framework/Versions/A/DirectoryService lib64/libdb2.dylib

The referenced post mentions changing a third library

libdb2e.dylib

however, I have only installed the db2 client to use the ibm_db python module and this library is not present.


The easiest solution to install ibm_db on MacOS is to run the below command:

pip3 install --no-binary "ibm_db" ibm_db

Regards,

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号