macos 如何让python在osx上加载dylib

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2488016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:49:27  来源:igfitidea点击:

how to make python load dylib on osx

pythonmacosdylib

提问by navicore

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

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

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

什么适用于 Linux 和 Netbsd 有一个符号链接 _mymodule.so --> ../.libs/libmymodule.so

but on osx, python's import mymodulewon't find

但是在 osx 上,pythonimport mymodule找不到

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

I've tried adding

我试过添加

export DYLD_LIBRARY_PATH=.:$DYLD_LIBRARY_PATH

to the script env, nogo. Any help appreciated.

到脚本环境,nogo。任何帮助表示赞赏。

-Ed

-埃德

update 4/6/10:

2010 年 4 月 6 日更新:

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.

使用下面来自 krunk 的信息解决。但是只是将 dylib 复制或 ln -s'ing 到 .so 名称并不能完全解决它。还是加载不出来。但是告诉 libtool 将 lib 与 -module 标志链接创建了一个可以加载的 .so lib。lib 的 Python 版本现在可以使用。

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.

现在,如果我能让 perl 库工作。我正在构建 swig perl、python、ruby 和 lua 库,而这个修复程序只让 python 和 lua 工作。

回答by jkyle

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.

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

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.

但是,请放心,即使在 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