Error reading “pickle” file, no module named 'Data'

和自甴很熟 提交于 2020-03-16 07:41:57

问题


I tried to read pickle file using Anaconda Navigator and have the following script.

import pickle
import sys, os 

with open('pickle1', 'rb') as fp:
    data_new = pickle.load(fp)

After running the window I get the following error window.

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-4-047bee0f1247> in <module>()
      3 
      4 with open('pickle1', 'rb') as fp:
----> 5     data_new = pickle.load(fp)

ModuleNotFoundError: No module named 'Data'

Can you please help me fix this issue? I tried to rename file to *.pkl, and *.csv formats, but it did not help. Original data file has no extension of its own.


回答1:


The program that created the pickle file did import Data and there are references to that module inside the pickled object. The program that loads the pickled object needs to be able to import that module to resolve those references. Either put the location of Data.py on your PYTHONPATH (or add the location to sys.path), or copy the module to where your program can find it.



来源:https://stackoverflow.com/questions/54195162/error-reading-pickle-file-no-module-named-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!