I am trying to get the basic Cython tutorial to work. So I have
hello.pyx:
def say_hello_to(name):
print("Hello %s!" % name)
And 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
)
However, trying to compile I get this error:
$ 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 is installed and scanning.so does appear to contain the symbol in question:
$ nm -gl /usr/local/lib/python2.7/site-packages/Cython/Compiler/Scanning.so | grep _PyCFunction_Check
U _PyCFunction_Check
Any ideas? I’m on OS X 10.7.5 using homebrew python 2.7.3.
Edit: As pointed out by @bdash’ comment below, U _PyCFunction_Check actually means that _PyCFunction_Check is undefined.
The solution was very simple: I uninstalled the brew python and the pip-installed Cython and reinstalled both after which everything seem to work.
I think the problem was that I had installed python with brew having only Xcode installed. In the meantime – before I installed Cython – I installed Apple’s Command Line Tools. So python and Cython was installed under different conditions which probably led to the error.