I'm trying to integrate a Cython module into my project and I'm having trouble getting it to compile correctly. I have traced my problem to this minimal example:
Say I have two files a.py
and b.pyx
located in the same directory, if I then do the following in a.py
:
import pyximport; pyximport.install()
import b
Then everything works fine, b.pyx
is compiled and imported successfully.
But if I instead do this in a.py
, assuming that a.py
and b.pyx
are located in dir1/dir2
:
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
import pyximport; pyximport.install()
import dir1.dir2.b
(which is somewhat nonsensical in this example but illustrates what's preventing me from importing a from elsewhere in my module hierarchy), I get the following exception:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 888, in _find_spec
AttributeError: 'PyxImporter' object has no attribute 'find_spec'
Is this expected behaviour or is something wrong with my installation? (I'm on Windows 10)
NOTE: there is another question with a very similar title on SO which does not answer my question at all.