Python链接错误

Python链接错误,python,macos,boost,anaconda,Python,Macos,Boost,Anaconda,我正在运行MacOSX10.8.4(Darwin12.4.0)和最新的Boost发行版(1.55.0)。我正在按照说明构建包含在我的发行版中的教程boostpython项目,它构建得很好 尽管如此,编译后的输出库依赖于Mac的系统Python,而不是我试图链接到的Python: [00:20] [tutorial] $ otool -L libboost_python.dylib libboost_python.dylib: libboost_python.dylib (compatib

我正在运行MacOSX10.8.4(Darwin12.4.0)和最新的Boost发行版(1.55.0)。我正在按照说明构建包含在我的发行版中的教程boostpython项目,它构建得很好

尽管如此,编译后的输出库依赖于Mac的系统Python,而不是我试图链接到的Python:

[00:20] [tutorial] $ otool -L libboost_python.dylib
libboost_python.dylib:
    libboost_python.dylib (compatibility version 0.0.0, current version 0.0.0)
    libpython2.7.dylib (compatibility version 2.7.0, current version 2.7.0)
    /opt/local/lib/libgcc/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.18.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
    /opt/local/lib/libgcc/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

[00:20] [tutorial] $ otool -L /usr/lib/libpython2.7.dylib
/usr/lib/libpython2.7.dylib:
    /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)
我尝试了以下配置,但似乎都没有改变要使用的Python:

$BOOST_ROOT/bootstrap.sh --with-python=$ANACONDA_PATH/bin/python

不管怎样,我都会得到这样的信息:

[01:58] [tutorial] $ python hello.py
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6
下面是比较的系统Python调用:

[01:58] [tutorial] $ /usr/bin/python hello.py
hello, world


类似:

在尝试了我在网络上找到的许多其他解决方案后,我失去了耐心,决定使用我自己的(非常糟糕的)黑客。我创建了两个bash脚本,一个用于将sys的Python链接到Anaconda,另一个用于重新链接回原始Python:

ana_py.sh

#!/usr/bin/env bash
# Link to Anaconda's Python
# $ANACONDA_PATH is the path to your anaconda folder

# BIN
cd /usr/bin

if [ ! -h python ]; then
    sudo mv python python_orig;
else
    sudo unlink python;
fi
sudo ln -s $ANACONDA_PATH/bin/python python

if [ ! -h python-config ]; then
    sudo mv python-config python-config_orig;
else
    sudo unlink python-config;
fi
sudo ln -s $ANACONDA_PATH/bin/python-config python-config

# INCLUDE
cd /usr/include

sudo unlink python2.7
sudo ln -s $ANACONDA_PATH/include/python2.7 python2.7

# LIB
cd /usr/lib

sudo unlink python2.7
sudo unlink libpython2.7.dylib
sudo ln -s $ANACONDA_PATH/lib/python2.7 python2.7
sudo ln -s $ANACONDA_PATH/lib/libpython2.7.dylib libpython2.7.dylib
#!/usr/bin/env bash
# Link to Mac OSX Python

# BIN
cd /usr/bin

sudo unlink python
if [ -f python_orig ]; then
    sudo mv python_orig python;
else
    sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python python;
fi

sudo unlink python-config
if [ -f python-config_orig ]; then
    sudo mv python-config_orig python-config;
else
    sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config python-config;
fi

# INCLUDE
cd /usr/include

sudo unlink python2.7
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 python2.7

# LIB
cd /usr/lib

sudo unlink python2.7
sudo unlink libpython2.7.dylib
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 python2.7
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/Python libpython2.7.dylib

sys_py.sh

#!/usr/bin/env bash
# Link to Anaconda's Python
# $ANACONDA_PATH is the path to your anaconda folder

# BIN
cd /usr/bin

if [ ! -h python ]; then
    sudo mv python python_orig;
else
    sudo unlink python;
fi
sudo ln -s $ANACONDA_PATH/bin/python python

if [ ! -h python-config ]; then
    sudo mv python-config python-config_orig;
else
    sudo unlink python-config;
fi
sudo ln -s $ANACONDA_PATH/bin/python-config python-config

# INCLUDE
cd /usr/include

sudo unlink python2.7
sudo ln -s $ANACONDA_PATH/include/python2.7 python2.7

# LIB
cd /usr/lib

sudo unlink python2.7
sudo unlink libpython2.7.dylib
sudo ln -s $ANACONDA_PATH/lib/python2.7 python2.7
sudo ln -s $ANACONDA_PATH/lib/libpython2.7.dylib libpython2.7.dylib
#!/usr/bin/env bash
# Link to Mac OSX Python

# BIN
cd /usr/bin

sudo unlink python
if [ -f python_orig ]; then
    sudo mv python_orig python;
else
    sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python python;
fi

sudo unlink python-config
if [ -f python-config_orig ]; then
    sudo mv python-config_orig python-config;
else
    sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config python-config;
fi

# INCLUDE
cd /usr/include

sudo unlink python2.7
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 python2.7

# LIB
cd /usr/lib

sudo unlink python2.7
sudo unlink libpython2.7.dylib
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 python2.7
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/Python libpython2.7.dylib


一旦您运行了
ana_py.sh
,您就可以运行
bootstrap.sh
b2
,&
bjam
,而无需提供/修改它们的任何Python参数/选项

我通过使用
安装名称工具
更改依赖的
dylib
名称来解决此问题:

  • 要更改您的
    libboost\u python.dylib的权限,请执行以下操作:

    chmod+w libboost\u python.dylib

  • 然后更改依赖项
    dylib

    install\u name\u工具-将libpython2.7.dylib/path/更改为/anaconda/lib/libpython2.7.dylib“libboost\u python.dylib”

  • 希望对你有帮助