Using imp.load_source () throws "No module named ..."

I am using a module impto download a python file (exists in:) /parent_folder/path/to/my_module/my_module.pyfrom source:

mod = imp.load_source("my_module", "/parent_folder/path/to/my_module/")

However, the file my_module.pyalso imports other modules recorded and saved in one folder:

    my_module.py
    ....
    ...
    from other_module import other_thing
    ...

load_sourcefails in relation No module named other_module. What would be the best way to upload a file that handles all imports? I would rather achieve this using the python import library function rather than usingsys.path

+4
source share
1 answer

Your path should contain the full path to the file, including ".py" at the end:

mod = imp.load_source("my_module", "/parent_folder/path/to/my_module/my_module.py")
0
source

All Articles