如何让 python 在 osx 上加载 dylib

发布于 2024-08-26 00:18:26 字数 655 浏览 3 评论 0原文

尝试从当前的“.”中加载共享库osx 上单元测试中的 dir。

在 Linux 和 Netbsd 上有效的是一个符号链接 _mymodule.so --> ../.libs/libmymodule.so

但在 osx 上,python 的 import mymodule 找不到

_mymodule.dylib --> ../.libs/libmymodule.dylib

我尝试添加

export DYLD_LIBRARY_PATH=.:$DYLD_LIBRARY_PATH

到脚本 env 中,nogo。任何帮助表示赞赏。

-Ed

更新 4/6/10:

用下面 krunk 的信息解决了。但仅仅将 dylib 复制或 ln -s 为 .so 名称并不能完全解决问题。还是无法加载。但是告诉 libtool 将 lib 与 -module 标志链接起来会创建一个可以加载的 .so lib。该库的 Python 版本现在可以使用。

现在如果我能让 perl lib 工作就好了。我正在构建 swig perl、python、ruby 和 lua 库,这个修复只让 python 和 lua 工作。

Trying to load a shared lib out of the current '.' dir in a unit test on osx.

What works on Linux and Netbsd there is a symlink _mymodule.so --> ../.libs/libmymodule.so

but on osx, python's import mymodule won't find

_mymodule.dylib --> ../.libs/libmymodule.dylib

I've tried adding

export DYLD_LIBRARY_PATH=.:$DYLD_LIBRARY_PATH

to the script env, nogo. Any help appreciated.

-Ed

update 4/6/10:

Solved with the info from krunk below. But just copying or ln -s'ing the dylib to a .so name didn't solve it completely. Still wouldn't load. But telling libtool to link the lib with the -module flag created a .so lib that would load. Python version of the lib works now.

Now if I could just get the perl lib working. I'm building swig perl, python, ruby, and lua libs and this fix only got python and lua working.

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

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

发布评论

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

评论(1

明天过后 2024-09-02 00:18:26

在 OS X 中也只需使用 *.so 作为模块扩展即可。我模糊地记得无法加载 .dylib,结果发现这是 python 本身的问题。 。 。但我现在找不到邮件列表帖子。

不过,请放心,即使在 OS X 上,您也遵循使用 *.so 的标准做法。整个框架中唯一的 *.dylib 是 libsvn_swig 的。

find /System/Library/Frameworks/Python.framework/Versions/2.6/ -name "*.so"

/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/X11/xcb/xcb.0.0.0.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/X11/xcb/xcb.0.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/X11/xcb/xcb.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/CoreGraphics/_CoreGraphics.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/OpenSSL/SSL.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/OpenSSL/crypto.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/OpenSSL/rand.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_appmain.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_carbon.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_inlines.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsbezierpath.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsbitmap.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsfont.so
 /System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsquickdrawview.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsview.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nswindow.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/CFNetwork/_manual.so

Just use *.so as your module extensions in OS X too. I have a vague memory of not being able to load .dylib's and it turning out to be an issue with python itself. . . but I can't find the mailing list post now.

However, rest assured you're following standard practice by using *.so's even on OS X. The only *.dylib's in the entire framework are the libsvn_swig ones.

find /System/Library/Frameworks/Python.framework/Versions/2.6/ -name "*.so"

/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/X11/xcb/xcb.0.0.0.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/X11/xcb/xcb.0.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/X11/xcb/xcb.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/CoreGraphics/_CoreGraphics.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/OpenSSL/SSL.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/OpenSSL/crypto.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/OpenSSL/rand.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_appmain.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_carbon.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_inlines.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsbezierpath.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsbitmap.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsfont.so
 /System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsquickdrawview.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsview.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nswindow.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/CFNetwork/_manual.so
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文