简体   繁体   English

python pickle.load()pkl文件抛出EOFError

[英]python pickle.load() pkl file throws EOFError

a friend generates a pickle file for me. 一个朋友为我生成了一个泡菜文件。 As he works on python 3 while I work on python 2, so he generated the file with 当他在python 3上工作而我在python 2上工作时,他用以下命令生成了文件

pickle.dump(some_file_to_be_pickled,open("path_to_that_file","wb+"),protocol=2)

While I tried to load it with 当我尝试加载它

the_file = pickle.load(open("path_to_that_file","rb"))

However, I met the EOFError, which looks like: 但是,我遇到了EOFError,它看起来像:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/pickle.py", line 1378, in load
   return Unpickler(file).load()
File "/usr/lib64/python2.7/pickle.py", line 858, in load
   dispatch[key](self)
File "/usr/lib64/python2.7/pickle.py", line 880, in load_eof
   raise EOFError
EOFError

My friend also tried to load this file on his computer with python 2 and he didn't have any problem doing that... 我的朋友还尝试使用python 2将此文件加载到他的计算机上,他这样做没有任何问题...

Any idea to fix this problem? 有解决这个问题的主意吗? By the way, I am using python 2.7.5 while he is using python 2.7.10 and python 3.5. 顺便说一句,我正在使用python 2.7.5,而他正在使用python 2.7.10和python 3.5。

I believe I had tried a something very similar and received the same result you are having; 我相信我尝试过非常相似的方法,并且得到了与您相同的结果; I was also running 2.7.5. 我也在运行2.7.5。 When I updated to 3.4, I didn't receive the error anymore and my function ran properly, so more than likely I would say the problem is your python is outdated. 当我更新到3.4时,我再也没有收到错误,并且我的函数正常运行,所以我更可能会说问题是您的python已过时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM