pandas python - 使用 pickle.load() 时没有名为 dill 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51597073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
python - No module named dill while using pickle.load()
提问by Ankush Bhatia
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.
我在 python 2.7 中安装了 dill,但是当我尝试解开我的模型时,它显示“没有名为 dill 的模块”。腌制文件包含Pandas系列。
EDIT : Here's the snapshot of the traceback on ElasticBeanstalk environment
编辑:这是 ElasticBeanstalk 环境回溯的快照
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
回答by Alok Nayak
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:
如果您的 Elastic beanstalk 或错误环境上的版本高于您的本地版本,则将您的 dill 包降级到在您的 EC2 或本地机器上运行的包。在您的本地机器上,检查当前的 dill 包:
pip freeze | grep -i 'dill'
e.g it outputs: dill==0.2.7.1 which is lower than what it is on beanstalk
例如它输出: dill==0.2.7.1 低于它在 beanstalk 上的
then downgrade using
然后使用降级
pip install dill==0.2.7.1
回答by Mike McKerns
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).
1)这看起来像一个 $PATH 问题(或者,类似地,一个链接问题)......你似乎至少有两个 python 安装(一个在 /opt/python,大概来自类似 macports 的东西,一个在 /usr/ lib64,可能还有 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.
我猜如果你仔细确认你使用的是哪个 python,哪个对应于pip
你使用的,你可能会发现你使用dill
的其他模块并不都在同一个 python 安装中。
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?
2)请注意,在回溯的第一行中,您似乎正在使用pickle.load
...如果您想使用dill
,您不应该dill.load
用来解开序列化对象吗?