Skip to content

serialized module fails if module is not in PYTHONPATH #123

@mmckerns

Description

@mmckerns

Question from SO: http://stackoverflow.com/questions/31884640/does-the-dill-python-module-handle-importing-modules-when-sys-path-differs

Can I use dill to serialize and then load that module in a different process that has a different sys.path which doesn't include that module? Right now I get import failures:

Here's an example. I run this script where the foo.py module's path is in my sys.path:

    % cat dill_dump.py 
    import dill
    import foo
    myFile = "./foo.pkl"
    fh = open(myFile, 'wb')
    dill.dump(foo, fh)

Now, I run this script where I do not have foo.py's directory in my PYTHONPATH:

    % cat dill_load.py 
    import dill
    myFile = "./foo.pkl"
    fh = open(myFile, 'rb')
    foo = dill.load(fh)
    print foo

It fails with this stack trace:

    Traceback (most recent call last):
      File "dill_load.py", line 4, in <module>
        foo = dill.load(fh)
      File "/home/b/lib/python/dill-0.2.4-py2.6.egg/dill/dill.py", line 199, in load
        obj = pik.load()
      File "/rel/lang/python/2.6.4-8/lib/python2.6/pickle.py", line 858, in load
        dispatch[key](self)
      File "/rel/lang/python/2.6.4-8/lib/python2.6/pickle.py", line 1133, in load_reduce
        value = func(*args)
      File "/home/b/lib/python/dill-0.2.4-py2.6.egg/dill/dill.py", line 678, in _import_module
        return __import__(import_name)
    ImportError: No module named foo

So, if I need to have the same python path between the two processes, then what's the point of serializing a python module?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions