Error reading “pickle” file, no module named '

2020-04-19 04:59发布

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条回答
smile是对你的礼貌
2楼-- · 2020-04-19 06:04

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.

查看更多
登录 后发表回答