Python ImportError without calling import
Okay, I'm stumped. I've looked around but can't find anything and can't figure out how to debug this. Basically python is throwing ImportError
in a line of code where I don't import anything. I have a pretty decent module ICgen
that contains a module ICgen_settings
.
Traceback (most recent call last):
File "<ipython-input-5-105e3826f255>", line 1, in <module>
IC = ICgen.load('IC.p')
File "diskpy/ICgen/ICgen.py", line 339, in load
ICobj.settings.load(input_dict['settings'])
File "diskpy/ICgen/ICgen_settings.py", line 484, in load
tmp_dict = pickle.load(open(settings_filename, 'rb'))
ImportError: No module named ICgen_settings
It doesn't make any sense to me. It clearly found ICgen_settings
, as it is throwing the error from within. Also, I don't make the call import
when it throws an error!
Any ideas?
source to share
When you try, pickle.load
tmp_dict
you need to load modules for any of the incoming data flow objects.
So, you were actually making a call import
when an error occurred: you were throwing an object of a specific type that needed a ICgen_settings
. NB: unpickling code can fire arbitrary Python statements. Never scatter objects that you don't trust!
Now why is this "explicitly found ICgen_settings
": No, just being in a named file ICgen_settings.py
does not mean the line import ICgen_settings
will succeed. Whether the import is successful depends on sys.path
which comes from the environment variable PYTHONPATH
. It also depends on the layout of the module ICgen_settings
: usually it would be the ICgen_settings
folder (not the file) containing the file __init__.py
.
source to share