我第一次尝试使用此basic cython tutorial。我在使用Python 3.6.6的conda环境中。
一切正常,直到我要导入模块为止:
In [1]: import helloworld
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-39f3e3c18221> in <module>
----> 1 import helloworld
ImportError: dlopen(/Users/billtubbs/cython-examples/helloworld.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libc++abi.1.dylib
Referenced from: /Users/billtubbs/anaconda/envs/py36/lib/libc++.1.dylib
Reason: image not found
我的环境似乎有问题,所以我尝试更新所有内容:
$ conda update numpy numba pandas scipy scikit-learn pytorch matplotlib statsmodels tensorflow keras cython
我见过类似的问题,但in different circumstances却没什么新的。
您如何开始调试这样的问题?
导致此问题的步骤:
helloworld.pyx:
print("Hello World")
setup.py:
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("helloworld.pyx")
)
根据教程:
(py36) $ python --version
Python 3.6.6
(py36) $ python setup.py build_ext --inplace
Compiling helloworld.pyx because it changed.
[1/1] Cythonizing helloworld.pyx
/Users/billtubbs/anaconda/envs/py36/lib/python3.6/site-packages/Cython/Compiler/Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /Users/billtubbs/cython-examples/helloworld.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
running build_ext
building 'helloworld' extension
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Users/billtubbs/anaconda/envs/py36/include -mmacosx-version-min=10.9 -m64 -fPIC -I/Users/billtubbs/anaconda/envs/py36/include -mmacosx-version-min=10.9 -m64 -fPIC -I/Users/billtubbs/anaconda/envs/py36/include/python3.6m -c helloworld.c -o build/temp.macosx-10.9-x86_64-3.6/helloworld.o
clang -bundle -undefined dynamic_lookup -Wl,-rpath,/Users/billtubbs/anaconda/envs/py36/lib -L/Users/billtubbs/anaconda/envs/py36/lib -headerpad_max_install_names -headerpad_max_install_names -mmacosx-version-min=10.9 -lc++ -Wl,-rpath,/Users/billtubbs/anaconda/envs/py36/lib -L/Users/billtubbs/anaconda/envs/py36/lib -Wl,-rpath,/Users/billtubbs/anaconda/envs/py36/lib -L/Users/billtubbs/anaconda/envs/py36/lib -headerpad_max_install_names -headerpad_max_install_names -mmacosx-version-min=10.9 -lc++ -Wl,-rpath,/Users/billtubbs/anaconda/envs/py36/lib -L/Users/billtubbs/anaconda/envs/py36/lib -arch x86_64 build/temp.macosx-10.9-x86_64-3.6/helloworld.o -L/Users/billtubbs/anaconda/envs/py36/lib -o /Users/billtubbs/cython-examples/helloworld.cpython-36m-darwin.so
(py36) $ ls
__pycache__
build
helloworld.c
helloworld.cpython-36m-darwin.so
helloworld.pyx
setup.py
如果需要,conda list
的输出为here。
更新
根据@merv建议,以下是otool的输出,“显示目标文件使用的共享库的名称和版本号”:
$ otool -L /Users/billtubbs/anaconda/envs/py36/lib/libc++.1.dylib
/Users/billtubbs/anaconda/envs/py36/lib/libc++.1.dylib:
@rpath/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libc++abi.dylib (compatibility version 1.0.0, current version 48.0.0)
@rpath/libc++abi.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)