Is it possible to create a Python 2.7 package using __init__.pyx
(compiled to __init__.so
)? If so how? I haven't had any luck getting it to work.
Here is what I have tried:
setup.py
:#!/usr/bin/env python from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext foo = Extension(name='foo.__init__', sources=['foo/__init__.pyx']) bar = Extension(name='foo.bar', sources=['foo/bar.pyx']) setup(name='foo', packages = ['foo'], cmdclass={'build_ext':build_ext}, ext_modules = [foo, bar])
foo/__init__.pyx
:import foo.bar cpdef hello_world(): print "hello world" foo.bar.blah()
foo/bar.pyx
:cpdef blah(): print "blah"
The above has the following behavior:
$ python -c 'import foo; foo.hello_world()'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named foo
I saw Python issue #15576 which was fixed by this Hg commit. Looking at the equivalent Git commit in the Git mirror of the Python Hg repository, I see that the commit is reachable from the Python v2.7.5 tag (as well as all subsequent v2.7.x versions). Was there a regression?