[英]Boost python on mac os x lion with custom python
我正在尝试使用boost python来使用自定义python库。 我有一个python源代码并使用以下命令构建boost.python:
./bootstrap.sh --with-python-root=../Python-2.7.2 --with-libraries=python
那么./b2
但是当我尝试在我的应用程序中使用boost.python时,我得到了
Fatal Python error: Interpreter not initialized (version mismatch?)
当我调用PyRun_SimpleString("import sys\\nprint sys.version");
,我得到2.7.2,正如我所料(和python的版本我构建boost.python而不是系统版本。)
有什么我想念的吗?
当我检查dylib链接的库时,我得到:
libboost_python.dylib (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.1)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)`
在我的Xcode目标中,我包含了--with-python-root参数文件夹中的python和boost / stage / lib的内容,
我下载了boost python并根据我使用Mac Ports安装的自定义python编译它,它似乎工作得很好。
我的步骤......
$ /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python
Python 2.7.2 (default, Nov 17 2011, 00:52:26)
$ sudo ./bootstrap.sh --with-libraries=python --with-python-root=/opt/local/Library/Frameworks/Python.framework/Versions/2.7
$ ./b2
$ cd /Users/YourName/Downloads/boost_1_48_0/libs/python/example/tutorial
$ ../../../../bjam
...patience...
...patience...
...found 1577 targets...
...updating 12 targets...
common.mkdir bin
common.mkdir bin/darwin-4.2.1
common.mkdir bin/darwin-4.2.1/debug
darwin.compile.c++ bin/darwin-4.2.1/debug/hello.o
darwin.link.dll bin/darwin-4.2.1/debug/hello_ext.so
common.copy libboost_python.dylib
common.copy hello_ext.so
common.mkdir bin/hello.test
common.mkdir bin/hello.test/darwin-4.2.1
common.mkdir bin/hello.test/darwin-4.2.1/debug
capture-output bin/hello.test/darwin-4.2.1/debug/hello
**passed** bin/hello.test/darwin-4.2.1/debug/hello.test
...updated 12 targets...
$ ls
Jamroot hello.cpp hello_ext.so
bin hello.py libboost_python.dylib
$ python
Python 2.7.2 (default, Nov 17 2011, 00:52:26)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello_ext
>>> hello_ext.greet()
'hello, world'
>>>
此外,如果您不需要自己构建所有内容,则可以使用mac端口来帮助您。 我没有尝试过,但它看起来像boost.python,虽然版本1.47而不是1.48。
$ port info boost
boost @1.47.0, Revision 2 (devel)
Variants: debug, no_single, no_static, openmpi, python24, python25, python26, python27, python31, python32, regex_match_extra,
universal
Description: Boost provides free portable peer-reviewed C++ libraries. The emphasis is on portable libraries which work well with
the C++ Standard Library.
Homepage: http://www.boost.org
Library Dependencies: zlib, expat, bzip2, icu
Platforms: darwin
License: Boost-1.0
Maintainers: adfernandes@macports.org
实际上,为了解决这个问题,我们可以看看我们的环境并比较你是否还有问题:)。
$ echo $ press-TAB
看起来你将boost python与错误版本的python(2.7.0)连接起来,而你的应用程序针对正确版本的python(2.7.2) - PyRun_SimpleString
与boost python无关,但是直接调用来自测试应用程序的Python API。
我使用project-config.jam
文件(在boost构建目录中)来配置应该构建哪个python boost-python,包括这一行(用于链接我的简单2.7安装):
using python : 2.7 : /Library/Frameworks/Python.framework/Versions/2.7/ ;
它可能是链接的dylib和真正使用的包含之间的不匹配。 一个简单的检查是将选项--debug-configuration
传递给bjam并检查包含和链接路径:
./b2 -q --prefix=your_install_dir YOU_OTHER_OPTIONS --debug-configuration install
应该在开始时产生这些行:
notice: [python-cfg] Configuring python...
notice: [python-cfg] user-specified version: "2.7"
notice: [python-cfg] user-specified cmd-or-prefix: "/Library/Frameworks/Python.framework/Versions/2.7"
notice: [python-cfg] Checking interpreter command "/Library/Frameworks/Python.framework/Versions/2.7/bin/python"...
notice: [python-cfg] running command '/Library/Frameworks/Python.framework/Versions/2.7/bin/python -c "from sys import *; print('version=%d.%d\nplatform=%s\nprefix=%s\nexec_prefix=%s\nexecutable=%s' % (version_info[0],version_info[1],platform,prefix,exec_prefix,executable))" 2>&1'
notice: [python-cfg] ...requested configuration matched!
notice: [python-cfg] Details of this Python configuration:
notice: [python-cfg] interpreter command: "/Library/Frameworks/Python.framework/Versions/2.7/bin/python"
notice: [python-cfg] include path: "/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7"
notice: [python-cfg] library path: "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config" "/Library/Frameworks/Python.framework/Versions/2.7/lib"
notice: [python-cfg] framework directory is "/Library/Frameworks/Python.framework"
你应该看到解释器,包含和二进制匹配( interpreter command
,分别include path
和library path
)。
如果不匹配,请检查usr/bin
的python-config
文件:它应该指向python.org安装路径。 如果没有,安装人员错过了它,应该修复它。
可能是链接的库未在/usr/lib
正确设置。 通过简单的ls -al /usr/lib/*python*
,您应该看到指向python.org安装的/usr/lib/libpython2.7.dylib
。 如果没有,python.org安装程序错过了它,应该修复它。
抱歉有点模糊。 我在1年前遇到过这个问题并通过做很多事情手工修复它直到它工作...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.