Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: can't pickle PyCapsule objects

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?

like image 833
Anna Iliukovich-Strakovskaia Avatar asked Oct 11 '25 13:10

Anna Iliukovich-Strakovskaia


1 Answers

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.

Update: As of https://github.com/uqfoundation/dill/pull/477 PyCapsule is now supported.

like image 137
Mike McKerns Avatar answered Oct 14 '25 09:10

Mike McKerns



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!