python - No module named dill while using pickle.load()
Asked Answered
B

2

9

I have dill installed in my python 2.7 but when I try to unpickle my model it says "No module named dill". The pickled file contains pandas series.

EDIT : Here's the snapshot of the traceback on ElasticBeanstalk environment

File "/opt/python/current/app/app/models/classification.py", line 663, in __init__
  self.lookupdict = pickle.load(open(<filepath>))
File "/usr/lib64/python2.7/pickle.py", line 1384, in load
  return Unpickler(file).load()
File "/usr/lib64/python2.7/pickle.py", line 864, in load
  dispatch[key](self)
File "/usr/lib64/python2.7/pickle.py", line 1096, in load_global
  klass = self.find_class(module, name)
File "/usr/lib64/python2.7/pickle.py", line 1130, in find_class
  __import__(module)
File "/opt/python/run/venv/local/lib64/python2.7/site-packages/gevent/builtins.py", line 93, in __import__
  result = _import(*args, **kwargs)
ImportError: No module named dill
Bryantbryanty answered 30/7, 2018 at 15:9 Comment(6)
What happens if you do a simple import dill?Chromosphere
Sometimes its the small things that hold up a programKilowatthour
Actually, it works on my local machine and even on the virtual environment on ec2 but when i deploy it with ElasticBeanstalk it throws this error. I'll try by importing dill. Thanks.Bryantbryanty
Nope, Didn't work.Bryantbryanty
Have you already installed dill (pip install dill`) on your destination environment?Faa
Yes, it's in the requirements. It's getting imported as wellBryantbryanty
D
15

If version on your Elastic beanstalk or error environment is greater than your local version then downgrade your dill package to the package which is working on your EC2 or local machine. On your local machine, check current dill package:

pip freeze | grep -i 'dill'

e.g it outputs: dill==0.2.7.1 which is lower than what it is on beanstalk

then downgrade using

pip install dill==0.2.7.1
Divulgence answered 7/8, 2018 at 8:24 Comment(0)
A
2

Two things:

1) This looks like a $PATH issue (or, similarly, a linking issue)... You seem to have at least two python installations (one at /opt/python, presumably from something like macports, and one at /usr/lib64, and possibly a third in a venv).

I'm guessing that if you carefully confirm which python you are using, and which corresponds to the pip you used, you might find dill and the other modules you are using are not all in the same python installation.

2) Note that in the first line of the traceback you seem to be using pickle.load... if you want to use dill, shouldn't you be using dill.load to unpickle the serialized object?

Amaliaamalie answered 31/7, 2018 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.