Cython:未找到符号:_PyCFunction_Check

时间:2013-01-26 02:48:18

标签: python cython

我想让basic Cython tutorial工作。所以我有

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

安装了

scanning.so

有什么想法吗?我在OS X 10.7.5上使用自制的python 2.7.3。

修改:正如@bdash在下面的评论所指出的那样,$ nm -gl /usr/local/lib/python2.7/site-packages/Cython/Compiler/Scanning.so | grep _PyCFunction_Check U _PyCFunction_Check 实际上意味着U _PyCFunction_Check未定义。

1 个答案:

答案 0 :(得分:1)

解决方案非常简单:我卸载了brew python和pip安装的Cython并重新安装了两者,之后一切似乎都有效。

我认为问题是我安装了python,只安装了Xcode。在此期间 - 在我安装Cython之前 - 我安装了Apple的命令行工具。所以python和Cython是在不同条件下安装的,这可能导致错误。