我知道这个非常老的问题Python 酸洗错误:TypeError: object pickle not returned list。numpy的问题?但给出的唯一答案相当模糊。
这是在 Python 3.6 中重现该问题的代码。
import pickle
from astroquery.irsa import Irsa
from astropy import units as u
# Query region.
table = Irsa.query_region("m31", catalog="fp_psc", spatial="Cone",
radius=.5 * u.arcmin)
# Dump table.
with open('table.pkl', 'wb') as f:
pickle.dump(table, f)
# This is where the issue appears.
with open('table.pkl', 'rb') as f:
table = pickle.load(f)
尝试加载腌制数据时,失败并显示:
Traceback (most recent call last):
File "/home/gabriel/Descargas/test.py", line 17, in <module>
table2 = pickle.load(f)
File "/home/gabriel/anaconda3/envs/cat-match/lib/python3.6/site-packages/astropy/table/column.py", line 238, in __setstate__
super_class.__setstate__(self, state)
File "/home/gabriel/anaconda3/envs/cat-match/lib/python3.6/site-packages/numpy/ma/core.py", line 5869, in __setstate__
super(MaskedArray, self).__setstate__((shp, typ, isf, raw))
TypeError: object pickle not returning list
我怎样才能解决这个问题?
使用conda,您可以在 Python 3 环境中安装要求:
conda install astropy
conda install -c astropy astroquery