0

I am not a proficient Python coder, hence this might be a basic question:

In my main python code, I load a python code file using (dynamically)

import imp
model = imp.load_source('name','c:/modeldir/modelfile.py')

modelfile.py does an import on the top:

from MyLib import MyLib

MyLib.py is in the same folder as modelfile.py

I get:

ImportError: No module named 'MyLib'

I have also tried:

import os
os.chdir('c:/modeldir')

just before the imp.load_source, did not help.

EDIT:

  • I am using Python 3.5.2
  • I've added an empty __init__.py file in 'c:/modeldir'

How to solve this?

Arnaud P
  • 12,022
  • 7
  • 56
  • 67
imran
  • 247
  • 2
  • 11

1 Answers1

0

The following made it work

sys.path.append('c:/modeldir')

This adds the folder to the python import path and then MyLib can be found

imran
  • 247
  • 2
  • 11