简体   繁体   English

如何让 ibm_db 或 PyDB2 python 模块在 Mac OS X 10.7 Lion 中与 DB2 一起使用?

[英]How do I get ibm_db or PyDB2 python modules to work with DB2 in 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?我使用这个问题/答案在 Lion 中安装 DB2: 如何在 Mac OS X 10.7 Lion 上安装 IBM DB2 Express-C?

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:配置我的数据库后,我可以从命令行使用 db2 执行查询,但是 python 模块 ibm_db 和 PyDB2 都无法导入并出现以下错误:

>>> 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?我该如何解决这个问题并让 ibm_db 和 PyDB2 与 Lion 中的 DB2 一起正常工作?

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).问题是 DirectoryService 框架中的一个特定符号最终在 Lion 中被删除(它在 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.由 DB2 Express-C 安装的 libdb2.dylib 尝试调用此 function,并在导入 python 模块时导致错误。

To work around this, you need to configure your environment to link against an older version of the DirectoryService framework.要解决此问题,您需要将环境配置为链接到旧版本的 DirectoryService 框架。 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).为此,您需要安装 Snow Leopard(它可能适用于旧版本,但我尚未对其进行测试,您将需要最新的版本,当然不是 Lion)。 You will find the DirectoryService framework installed here:您将在此处找到安装的 DirectoryService 框架:

/System/Library/Frameworks/DirectoryService.framework/

Copy that directory from a Snow Leopard installation to any location you want in your Lion installation.将该目录从 Snow Leopard 安装复制到您希望在 Lion 安装中的任何位置。 For this example, I copied the DirectoryService.framework directory into a directory named OldFrameworks in ~:对于此示例,我将 DirectoryService.framework 目录复制到 ~ 中名为 OldFrameworks 的目录中:

~/OldFrameworks/DirectoryService.framework/

Set the environment variable $DYLD_LIBRARY_PATH to contain the path to the actual library:设置环境变量$DYLD_LIBRARY_PATH以包含实际库的路径:

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.执行上述命令的任何环境都将配置为允许 python 导入 ibm_db 或 PyDB2。 Add it to your.profile, .bashrc, etc. to permanently configure your environment.将其添加到 your.profile、.bashrc 等以永久配置您的环境。 Remember, though, this means all commands executed in the configured environment will attempt to link against the snow leopard version of DirectoryService.但是请记住,这意味着在配置的环境中执行的所有命令都将尝试链接到雪豹版本的 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.谨慎的做法是只在需要的 shell 中设置 DYLD_LIBRARY_PATH。

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您可以使用 install_name_tool 更改 db2 库以查看 DirectoryService.framework 的复制版本,因此您不必更改 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.完全归功于以下内容,我只是通过在 Lion 上安装 db2 / ibm_db 的过程来更新此线程,并通过 Google 发现此线程是热门话题之一。

http://www.ibm.com/developerworks/forums/thread.jspa?threadID=238136&start=30&tstart=0 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 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将 Snow Leopard DirectoryService.framework 复制到

/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.但是,我只安装了 db2 客户端来使用 ibm_db python 模块,并且该库不存在。

The easiest solution to install ibm_db on MacOS is to run the below command:在 MacOS 上安装 ibm_db 最简单的解决方案是运行以下命令:

pip3 install --no-binary "ibm_db" ibm_db

Regards,问候,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM