我有一個Python中的Pickle模塊的問題。我想插入一些4參數數據,所以我想構建和存儲插補器,以便它可以在另一個代碼中重用,而不必在執行時重新生成。實際上,每次執行代碼時都會重新創建它。 所有我能得到的是這樣的信息:Python pickle:Can not pickle <class'interpnd.LinearNDInterpolator'>:找不到它作爲interpnd.LinearNDInterpolator
"PicklingError: Can't pickle : it's not found as interpnd.LinearNDInterpolator"
我吹我的頭,試圖找出如何解決它,這是我的代碼(Python的V2.7)的簡化versione,和回溯如下提前 感謝您的建議
a1,a2,a3,a4 = np.mgrid[paramvariation]
pts = np.array([a1.ravel(),a2.ravel(),a3.ravel(),a4.ravel()]).T
sr=paramvalues.ravel()
LinearNDInterp = interp.interpnd.LinearNDInterpolator(pts,sr,fill)
fileid=open("try.out",'w')
pickle.dump(LinearNDInterp,fileid)
fileid.close()
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\startup.py", line 128, in runfile
execfile(filename, glbs)
File "tryout.py", line 516, in <module>
main("")
File "tryout.py", line 354, in main
pickle.dump(LinearNDInterp,fileid)
File "C:\Python27\lib\pickle.py", line 1370, in dump
Pickler(file, protocol).dump(obj)
File "C:\Python27\lib\pickle.py", line 224, in dump
self.save(obj)
File "C:\Python27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python27\lib\pickle.py", line 401, in save_reduce
save(args)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 562, in save_tuple
save(element)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 748, in save_global
(obj, module, name))
PicklingError: Can't pickle <class 'interpnd.LinearNDInterpolator'>: it's not found as interpnd.LinearNDInterpolator
謝謝你,我已經按照這個bug評論中突出顯示的更正,但錯誤仍然存在......並且修改後的文件generate_interpnd根本沒有執行......我錯過了什麼嗎? – rogotad 2012-03-23 13:39:58
這看起來像在構建過程中執行的文件。 – 2012-03-23 13:45:29