Imp.load_source () throws "No Module Named" Python 2.7 Error

I am currently using Python 2.7 and I am trying to upload a file as follows:

myPlt = imp.load_source('SourceFile', 'path/to/SourceFile.py') 

However, SourceFile.py imports the OtherModule module, which is located in the same directory as SourceFile. The package structure is as follows:

 /path .../to ...SourceFile.py ...OtherModule.py ...__init__.py 

When I run load_source, I get the error message "ImportError: No module named OtherModule"

Is my load_source wrong? Is there an alternative way that I should import a SourceFile?

+5
source share
1 answer

Try:

imp.load_source ("directory", "directory" + "filename.py")

0
source

All Articles