Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pickle AttributeError: Can't get attribute 'Wishart' on <module '__main__' from 'app.py'>

I already run my code to load my variable saved by pickle. This my code

import pickle 
last_priors_file = open('simpanan/priors', 'rb') 
priors = pickle.load(last_priors_file)

and i get error like this : AttributeError: Can't get attribute 'Wishart' on <module '__main__' from 'app.py'>

like image 526
Anugrah Dwiatmaja Putra Avatar asked May 17 '18 14:05

Anugrah Dwiatmaja Putra


1 Answers

This happens because the pickled data was saved when the script is run as __name__ == '__main__' and so it saves the location of Wishart as __main__.Wishart. Then, when you run your next script to load the data, there is no Wishart in scope so it fails.

The fix in this case is to simply add from wherever import Wishart before the call to pickle.load.

like image 149
aconz2 Avatar answered Oct 02 '22 21:10

aconz2