nol*_*olk 6 python linux macos ctypes dynamic-linking
我有一个C++库repeater.so,我可以通过以下方式从Linux加载Python:
import numpy as np
repeater = np.ctypeslib.load_library('librepeater.so', '.')
Run Code Online (Sandbox Code Playgroud)
但是,当我在Mac OS X(Snow Leopard,32位)上编译相同的库并获取repeater.dylib,然后在Python中运行以下内容时:
import numpy as np
repeater = np.ctypeslib.load_library('librepeater.dylib', '.')
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
OSError: dlopen(/mydir/librepeater.dylib, 6): no suitable image found. Did find:
/mydir/librepeater.dylib: mach-o, but wrong architecture
Run Code Online (Sandbox Code Playgroud)
在Mac OS X上,我是否必须采用不同的方法在Python中加载动态库?
Ned*_*ily 11
这不仅仅是dylib中可用的架构问题; 它也是Python解释器运行的体系结构的问题.如果你在OS X 10.6中使用Apple提供的Python 2.6.1,默认情况下它会尽可能以64位模式运行.既然你说你的库被编译为32位,你需要强制Python以32位模式运行.对于Apple提供的Python,一种方法是设置一个特殊的环境变量:
$ python -c "import sys; print sys.maxint"
9223372036854775807
$ export VERSIONER_PYTHON_PREFER_32_BIT=yes
$ python -c "import sys; print sys.maxint"
2147483647
Run Code Online (Sandbox Code Playgroud)
有关man 1 python详细信息,请参阅Apple的.
没有。正如错误消息所示,您的 python 和librepeater.dylib文件之间存在体系结构不匹配。用于file检查架构librepeater.dylib是什么;您的 python 将使用未列出的其中之一来构建。
| 归档时间: |
|
| 查看次数: |
5785 次 |
| 最近记录: |