Reputation: 43
I have an extension module named foo.c and a utility python file utils.py which extends some basic functionality of my extension module. Now I want to use utils as a subpackage of foo (foo.utils). Like the following:
from foo import bar
from foo.utils import test
...
I tried various distutils configurations, but in the end without success. Often my py_modules overwrite my ext_modules. Here is sample distutils setup:
from distutils.core import setup, Extension
setup(name='foo',
version='1.0',
py_modules = [foo.utils]
ext_modules=[Extension('foo', ['foo.c'])],
)
My directory looks like the following
|_ foo/__init__.py
|_ foo/utils.py
|_ foo.c
|_ setup.py
When I try to just use my ext_module or py_module both work fine. Does anyone has a hint or isn't it possible with distutils?
Upvotes: 4
Views: 1128
Reputation: 375932
You won't be able to have a C extension named foo and also a module named foo.utils. Rename your extension to _foo.c, and then create foo/__init__.py
which imports from _foo.
BTW, this isn't a distutils issue, it has to do with the required structure of foo to get foo.utils working. "foo" can either be a module or a package, but not both.
Upvotes: 5