0

I'm using the basic "hello world" demo straight out of the Cython documentation. It works fine unless I try to import py2app in the same setup.py file:

import py2app
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("helloworld", ["helloworld.pyx"])]
)

Py2app itself works fine as long as I pre-generate the .c files for my Cython modules. But if I haven't, then build_ext fails with:

running build_ext
gcc-4.2 not found, using clang instead
building 'helloworld' extension
clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c helloworld.c -o build/temp.macosx-10.6-intel-2.7/helloworld.o
clang: error: no such file or directory: 'helloworld.c'
clang: error: no input files
error: command 'clang' failed with exit status 1

If I comment out import py2app in setup.py, build_ext works fine and I get the missing intermediate step in my compilation:

...
gcc-4.2 not found, using clang instead
cythoning helloworld/helloworld.pyx to helloworld/helloworld.c
building 'helloworld' extension
...

So what is it about py2app that breaks Cython? And what can I do about it? I'd like to have just one setup.py for my project, obviously.

I have Cython 0.18 and py2app 0.7.2, installed from PyPI. I'm using Mac OS X 10.8 with the python.org Python 2.7.3, not Apple's build.

jab
  • 4,053
  • 3
  • 33
  • 40
  • What happens when you replace "import py2app" by "import setuptools"? Py2app itself doesn't patch distutils, but does use setuptools. – Ronald Oussoren Mar 31 '13 at 13:25
  • Also: this might be related to [this issue](https://bitbucket.org/tarek/distribute/issue/195) in the distribute issue tracker. – Ronald Oussoren Mar 31 '13 at 13:45
  • Hooray, that was the problem. `import setuptools` also broke Cython. Installing `distribute` (0.6.36) instead of `setuptools` (0.6.c11) fixed it. Please submit as an answer and I'll accept it... – jab Apr 07 '13 at 03:52

1 Answers1

1

The build fails because py2app uses setuptools, and older versions of setuptools (and distribute) are not compatible with Cython.

The solution is to install a newer version of setuptools or distribute.

Ronald Oussoren
  • 2,715
  • 20
  • 29
  • For completeness, I did have the newest version of setuptools available on PyPI. Distribute is, of course, a drop-in replacement for setuptools and includes the Cython fix. – jab Apr 08 '13 at 17:06