导入dlib找不到ImportError符号:_PyClass_Type

时间:2017-08-28 16:09:05

标签: python boost dlib

当我在Python 3.6中运行import dlib时,我收到以下错误:

Traceback (most recent call last):
File "demo.py", line 3, in <module>
import dlib
File "/usr/local/lib/python3.6/site-packages/dlib/__init__.py", line 1, in <module>
from .dlib import *
ImportError: dlopen(/usr/local/lib/python3.6/site-packages/dlib/dlib.so, 2): Symbol not found: _PyClass_Type
Referenced from: /usr/local/opt/boost-python/lib/libboost_python-mt.dylib
Expected in: flat namespace in /usr/local/opt/boost-python/lib/libboost_python-mt.dylib

我尝试取消boost-python然后brew install boost-python --with-python3,但没有结果。

这也是otool -L /usr/local/lib/libboost_python.dylib

的输出
/usr/local/lib/libboost_python.dylib:
/usr/local/opt/boost-python/lib/libboost_python.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.5.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)

我在链接错误方面感觉不是很强烈,任何想法都会受到赞赏。

1 个答案:

答案 0 :(得分:2)

检查文件夹/usr/local/opt/boost-python/lib/,有以下文件:

/u/l/l/p/site-packages> cd /usr/local/opt/boost-python/lib/
/u/l/C/b/1/lib> ls
libboost_numpy-mt.a       libboost_numpy3-mt.a      libboost_python-mt.a      libboost_python3-mt.a
libboost_numpy-mt.dylib   libboost_numpy3-mt.dylib  libboost_python-mt.dylib  libboost_python3-mt.dylib
libboost_numpy.a          libboost_numpy3.a         libboost_python.a         libboost_python3.a
libboost_numpy.dylib      libboost_numpy3.dylib     libboost_python.dylib     libboost_python3.dylib

创建一个备份这些文件的文件夹,然后将编号为3的文件复制到没有编号3的文件。例如,将libboost_python3-mt.dylib复制到libboost_python-mt.dylib,然后就可以了。