I am writing some code in cython, and I have some "Packages “within” modules". — This is actually a follow up to my question there, and the structure should be the same. The problem is that this is cython, so I'm dealing with .so
's not .py
's.
Having __init__.so
works to the extent that,
import mystuff
will work, but it seems to mask all the subpackages below. That is,
import mystuff.test.test1
will not. I get an ImportError: No module named ...
error.
How can I work around this? Is there something I need to add to the .pyx
before compiling it to .c
? Or perhaps I can rename __init__.so
to something else, and somehow pull it into the __init__.py
(Note, an __init__.py
still needs to exist alongside the .so
to show it's a package)? Or something else.
Update: __path__
attribute not defined for .so
packages ...
Ok, I had a thought that maybe I could get around this by manipulating the __path__
attribute of the package. Interestingly enough, this is defined for .py
packages, but causes an error with the .so
's. It's not a solution, but I wonder if it is the root of the problem.
Have your Cython code be in a different file than __init__.py
, and import it into a normal python __init__.py
See my answer to your previous question.
Probably the most simple solution to given problem would be to rename your __init__.so
module into something like _native.so
. Afterwards you can create __init__.py
which would contain following line:
from _native import *
And it should work as you describe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With