如何让 ibm_db 或 PyDB2 python 模块与 Mac OS X 10.7 Lion 中的 DB2 配合使用?

发布于 2024-11-29 18:01:44 字数 815 浏览 4 评论 0原文

我使用这个问题/答案在 Lion 中安装 DB2:如何在 Mac OS X 10.7 Lion 上安装 IBM DB2 Express-C?

配置数据库后,我可以从命令行使用 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

如何修复此问题并使 ibm_db 和 PyDB2 与 Lion 中的 DB2 一起正常工作?

编辑:将答案移至答案

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风向决定发型 2024-12-06 18:01:44

答案:

问题在于 DirectoryService 框架中的一个特定符号最终在 Lion 中被删除(在 10.2 中已弃用)。由 DB2 Express-C 安装的 libdb2.dylib 尝试调用此函数,并在导入任一 python 模块时导致错误。

要解决此问题,您需要将环境配置为链接到旧版本的 DirectoryService 框架。为此,您需要安装 Snow Leopard(它可能适用于旧版本,但我还没有测试过它,您需要可以使用的最新版本,当然不是 Lion)。您将在此处找到安装的 DirectoryService 框架:

/System/Library/Frameworks/DirectoryService.framework/

将该目录从 Snow Leopard 安装复制到您在 Lion 安装中所需的任何位置。对于此示例,我将 DirectoryService.framework 目录复制到 ~ 中名为 OldFrameworks 的目录中:

~/OldFrameworks/DirectoryService.framework/

设置环境变量 $DYLD_LIBRARY_PATH 以包含实际库的路径:

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

执行上述命令的任何环境将配置为允许 python 导入 ibm_db 或 PyDB2。将其添加到您的 .profile、.bashrc 等中以永久配置您的环境。但请记住,这意味着在配置的环境中执行的所有命令都将尝试链接到 DirectoryService 的雪豹版本。这可能会导致其他工具出现错误(我还没有遇到过任何错误)。谨慎的做法是仅在需要的 shell 中设置 DYLD_LIBRARY_PATH。

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.

无人问我粥可暖 2024-12-06 18:01:44

您可以使用 install_name_tool 更改 db2 库以查看 DirectoryService.framework 的复制版本,因此您不必更改 DYLD_LIBRARY_PATH

完全归功于以下内容,我只是更新此线程已经完成安装 db2 / 的过程Lion 上的 ibm_db 并发现该线程是 Google 的热门话题之一。

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

以及此处描述的其他选项:

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

答案(上面的线程应该消失):

将 Snow Leopard DirectoryService.framework 复制到

/opt/SL_Frameworks/DirectoryService.framework 

然后

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

引用的帖子提到更改第三个库,

libdb2e.dylib

但是,我只安装了 db2 客户端来使用 ibm_db python 模块,并且该库不存在。

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.

岁月苍老的讽刺 2024-12-06 18:01:44

在 MacOS 上安装 ibm_db 最简单的解决方案是运行以​​下命令:

pip3 install --no-binary "ibm_db" ibm_db

问候,

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

pip3 install --no-binary "ibm_db" ibm_db

Regards,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文