Reputation: 12663
I'm trying to build a Python extension and package it up using distutils but the extension installs in the root package no matter how I name it. My directory layout looks like this:
foo/bar/extension.c
My setup.py
looks like this:
from distutils.core import setup
from distutils.extension import Extension
setup(name='foo.bar.extension',
cmdclass={'build_ext': build_ext},
ext_modules=[Extension('foo.bar.extension',
sources=['foo/bar/extension.c'])]
)
I set up a virtualenv
and run
python setup.py install
Then in my Python shell:
>>> import foo.bar.extension
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named invest_cython_core
>>> import extension #This works!
What can I change so that the first import statement to works and the second one to fails?
Upvotes: 1
Views: 1336
Reputation: 6907
I think you need to have foo/__init__.py
and foo/bar/__init__.py
so that distutils installs first these packages and then the extension module. (An error would be better than a silent misbehavior here, I shall open a bug report so that distutils2 behaves better.)
Are you using a custom build_ext class? (asking because of cmdclass={'build_ext': build_ext}
in your example) That may play a part in the issue.
Upvotes: 1