我正在尝试使用基本的 Cython 教程。所以我有
hello.pyx
:
def say_hello_to(name):
print("Hello %s!" % name)
并且setup.py
:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("hello", ["hello.pyx"])]
setup(
name = 'Hello world app',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
但是,尝试编译时出现此错误:
$ python setup.py build_ext --inplace
running build_ext
failed to import Cython: dlopen(/usr/local/lib/python2.7/site-packages/Cython/Compiler/Scanning.so, 2): Symbol not found: _PyCFunction_Check
Referenced from: /usr/local/lib/python2.7/site-packages/Cython/Compiler/Scanning.so
Expected in: flat namespace
in /usr/local/lib/python2.7/site-packages/Cython/Compiler/Scanning.so
error: Cython does not appear to be installed
Cython已安装,并且scanning.so
确实包含有问题的符号:
$ nm -gl /usr/local/lib/python2.7/site-packages/Cython/Compiler/Scanning.so | grep _PyCFunction_Check
U _PyCFunction_Check
有任何想法吗?我在 OS X 10.7.5 上使用自制 python 2.7.3。
编辑:正如下面@bdash 的评论所指出的,U _PyCFunction_Check
实际上意味着这 _PyCFunction_Check
是未定义的。