问题
When I run import dlib in Python 3.6 I get the following error:
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
I tried unistalling boost-python and then brew install boost-python --with-python3 with no result.
Here is also the output of 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)
I am not feeling very strong in terms of linking errors, any ideas would be appreciated.
回答1:
Check folder /usr/local/opt/boost-python/lib/, there are these files:
/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
Create a folder backup these files, then copy files with number 3 to files without number 3. For example, copy libboost_python3-mt.dylib to libboost_python-mt.dylib, then it will work.
来源:https://stackoverflow.com/questions/45923202/import-dlib-importerror-symbol-not-found-pyclass-type