Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top