简体   繁体   English

在OSX Lion上强制链接到特定的python库

[英]Impose linking to specific python library on OSX Lion

I am building a python module from c++ files, using swig, and I also have a local build of python 2.7 in my home directory, on OSX 10.8. 我正在用c ++文件构建一个python模块,使用swig,我的主目录中也有一个本地版本的python 2.7,在OSX 10.8上。 I want to build with my local python, but osx has a system python, and that causes some trouble. 我想使用我的本地python构建,但是osx有一个系统python,这会导致一些麻烦。 I get the following error 我收到以下错误

>>> import example
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6

which according to browsing around, it's due to my python executing, but the module linking against the system python. 根据浏览,这是由于我的python执行,但模块链接系统python。

I deployed a small swig example, as from tutorial , and then linked as follows 从教程中部署了一个小的swig示例,然后按如下方式进行链接

gcc -shared -I builddir/include/python2.7/ example.c example_wrap.c \
     -o _example.so -L builddir/lib/python2.7/ -lpython2.7

Sure enough, the _example.so keeps binding against the system python, probably because frameworks come first in the resolution, although I am not sure if this is at linking time or at execution time. 果然,_example.so继续绑定系统python,可能是因为框架在分辨率中排在第一位,尽管我不确定这是在链接时还是在执行时。

_example.so:
    _example.so (compatibility version 0.0.0, current version 0.0.0)
    /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.2)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

how can I force it to bind against my own python library? 如何强制它绑定我自己的python库?

Edit : I successfully managed to make it import by doing a 编辑 :我成功地设法通过做一个导入它

 install_name_tool -change 
       /System/Library/Frameworks/Python.framework/Versions/2.7/Python
       @executable_path/../lib/libpython2.7.dylib

but it feels like a hack. 但感觉就像一个黑客。 Can't I just let the linker find the library for me and put the appropriate reference in it? 我不能让链接器为我找到库并在其中放入适当的引用吗? Can't I just specify the library name (libpython2.7.dylib) and let it resolve at runtime as it happens in Linux ? 我不能只指定库名(libpython2.7.dylib)并让它在运行时解析,因为它发生在Linux中?

You will need to test the solution, because I don't have tan OSX machine to test it here, but I think this can solve your problem: 你需要测试解决方案,因为我没有tan OSX机器来测试它,但我认为这可以解决你的问题:

Create a (or edit one) run script and change your alias or your PATH variable: 创建(或编辑一个)运行脚本并更改别名或PATH变量:

alias python='/your/local/python'
PATH=/your/local/python:$PATH

# Run your app here

Let me know if this helps. 如果这有帮助,请告诉我。

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

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