I run into this problem when testing some code interactively on PyCharm 4.5.3 Community edition. Pickling class objects does not work in the interactive console. Here my minimal code:
import pickle
class Test:
def __init__(self, name):
self.name = name
with open('testdata.pkl', 'wb') as output:
test1 = Test('Fritz')
pickle.dump(test1, output, pickle.HIGHEST_PROTOCOL)
test2 = Test('Hans')
pickle.dump(test2, output, pickle.HIGHEST_PROTOCOL)
Running this on an interactive console in PyCharm 4.5.3 using Python 3.4.3 on OSX 10.10.4, I get the following error:
Traceback (most recent call last):
File "<input>", line 7, in <module> _pickle.PicklingError:
Can't pickle <class 'Test'>: attribute lookup Test on builtins failed
The code works when executed with 'Run' in PyCharm. It's not a big thing but it cost me quite some time as I was not aware that there can be differences between running code in a 'fresh' interactive console, compared to execution using the 'Run' command. Could be the same issue as here