TypeError: can't pickle PyCapsule objects

Question:

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?

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.

Answered By: Mike McKerns