[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Relative import cannot find .so submodule?

Patrick Stinson <patrickkidd at> writes:
> I have a module named rtmidi, and its C submodule named rtmidi/_rtmidi. The distills script builds successfully and successfully creates a build/lib dir with a rtmidi dir in it and the submodule file rtmidi/ I have set PYTHONPATH to this lib dir, but rtmidi/ gives the following error:
> Traceback (most recent call last):
>   File "", line 6, in <module>
>     from pkmidicron import MainWindow, util, ports
>   File "/Users/patrick/dev/pkmidicron/pkmidicron/", line 1, in <module>
>     from .mainwindow import *
>   File "/Users/patrick/dev/pkmidicron/pkmidicron/", line 2, in <module>
>     import rtmidi
>   File "/Users/patrick/dev/pkmidicron/pyrtmidi/build/lib/rtmidi/", line 1, in <module>
>     from ._rtmidi import *
> ModuleNotFoundError: No module named 'rtmidi._rtmidi?
> How does the module finder work in the import system? I assume ti automatically resolves the name to _rtmidi? I didn?t have any luck reading the docs on the import system.

I think the extension module should be found.

However, an extension module must satify further conditions
(apart from being found), e.g. it must contain a public initialization
function with a name derived from the module name (and dependent
on the major Python version). Maybe, your so does not fulfill one of
those conditions?