我一直在使用dill
,因为this question of mine得到了软件包维护者的很好的回答。
最近,在我的用例中,我收到以下错误:
stored_env = dill.load(f_in)
File "A:\anaconda\lib\site-packages\dill\dill.py", line 250, in load
obj = pik.load()
File "A:\anaconda\lib\pickle.py", line 864, in load
dispatch[key](self)
KeyError: '\x7f'
这意味着什么?
我正在使用由dill
'0.2.5'
版本pip install dill
我尝试设置dill.detect.trace(True)
,但我没有输出。
编辑:以下是一个不起作用的最小示例:
#test.py
import numba as nb
import numpy as np
@nb.jit(nopython=True)
def my_fast_vector_add(x, y):
num_elements = x.shape[0]
z = np.zeros(num_elements, dtype=np.float64)
for i in range(num_elements):
z[i] = x[i] + y[i]
return z
class Environment():
def __init__(self):
self.x = np.random.rand(10)
self.y = np.random.rand(10)
def my_vector_add(self):
return my_fast_vector_add(self.x, self.y)
将所有内容放在一起的代码:
#doit.py
import test
import dill
import os
import shutil
import gzip
env = test.Environment()
print "init add result: ", env.my_vector_add()
pkl_path = "test.pkl"
with open(pkl_path, 'w') as f:
dill.dump(env, f)
compressed_path = "test.zip"
with open(pkl_path, 'r') as f_in, gzip.open(compressed_path, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
os.remove(pkl_path)
stored_env = None
with gzip.open(compressed_path, 'r') as f_in:
stored_env = dill.load(f_in)
print "loaded add result: ", stored_env.my_vector_add()
产生的错误是:
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "A:/dill_issue/doit.py", line 25, in <module>
stored_env = dill.load(f_in)
File "A:\anaconda\lib\site-packages\dill\dill.py", line 250, in load
obj = pik.load()
File "A:\anaconda\lib\pickle.py", line 864, in load
dispatch[key](self)
File "A:\anaconda\lib\pickle.py", line 886, in load_eof
raise EOFError
EOFError
答案 0 :(得分:1)
显然答案是从dill-0.2.5
升级到dill-0.2.6.dev0
。