Why might this happen?
import window; print "LOADED"; data = cPickle.loads(data)
The result is:
LOADED
Traceback (most recent call last):
...
import window; print "LOADED"; data = cPickle.loads(data)
exceptions.ImportError: No module named window
It loads the module fine if I do import window
, but when loading with cPickle
it doesn't seem to work.
For some additional info which is likely relevant:
The module I saved the file in is in project1\MODULE\submodule\main.py
. The window
module is project1\MODULE\window.py
. main.py
begins:
import sys
sys.path.append("..\\..")
sys.path.append("..")
...
import window
The module I'm attempting to load from is in project2\project2sub\MODULE\data.py
, with no messing with the sys
path.
MODULE
is the same in both cases: the module I want to load is project2\project2sub\MODULE\window.py
.
Could the sys.path
appending mess this up somehow?
Pickle depends upon the module path. No matter how you load modules, if you don't mess with
sys.path
, pickle loading and saving should work. However, if you doimport module.foo
in one place, andsys.path.append('module'); import foo
, you have two different module paths: in the first instance the module path ismodule.foo
while in the second it is justfoo
. These are not equivalent and that'll prevent pickle from working properly.Check to make sure that you're importing classes in the loading programing in the same manner as you are in the saving program.
Saving:
Loading
NOT:
Saving:
Loading: