TypeError: can't pickle PyCapsule objects

浪尽此生 提交于 2021-01-24 07:50:07

问题


I use dill to save ML model to file.

When I run my tests with python -m unittest it works. But if I try run tests with python setup.py test it getting error TypeError: can't pickle PyCapsule objects in raw where I try to save model.

My settings in setup.py for testing:

test_suite='tests', tests_require=['pytest']

Error:

  File "/Users/anna/anaconda3/lib/python3.6/site-packages/dill/_dill.py", line 1055, in save_builtin_method
    pickler.save_reduce(_get_attr, (module, obj.__name__), obj=obj)
  File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 610, in save_reduce
    save(args)
  File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 736, in save_tuple
    save(element)
  File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/Users/anna/anaconda3/lib/python3.6/site-packages/dill/_dill.py", line 1260, in save_module
    state=_main_dict)
  File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 634, in save_reduce
    save(state)
  File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/Users/anna/anaconda3/lib/python3.6/site-packages/dill/_dill.py", line 893, in save_module_dict
    StockPickler.save_dict(pickler, obj)
  File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 821, in save_dict
    self._batch_setitems(obj.items())
  File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 847, in _batch_setitems
    save(v)
  File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 496, in save
    rv = reduce(self.proto)
TypeError: can't pickle PyCapsule objects

Could you help me to know why it doesn't work?


回答1:


I'm the dill author. This is a known open issue for dill. See: https://github.com/uqfoundation/dill/issues/106. Essentially, a serialization function for PyCapsule objects has not yet been registered in dill.



来源:https://stackoverflow.com/questions/53883328/typeerror-cant-pickle-pycapsule-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!