cPickle not available for Python3.0

41 views
Skip to first unread message

Sonice

unread,
Jan 18, 2021, 2:27:25 AM1/18/21
to OpenQuake Users
I am trying to import database, as per gmpe-smtk-guide. But according to google, there is no cPickle in Python3, but the guide is using it. Also I tried a solution as suggested in google, but that also didn't work. Is there any new way to load these metadatafile, or some tweaks so that we can use cPickle or something like that? 
Thank You!

Case 1:::
------------------------------
import cPickle

db1 = cPickle.load(open(r"F:\Python_Sonice\ngawest_db\metadatafile.pkl", "r"))

O/P -- ErrorMsg::
module not found
----------------------------------------------------------------
Case 2
-------------------------------------------------
import _pickle as cPickle  
import cPickle

db1 = cPickle.load(open(r"F:\Python_Sonice\ngawest_db\metadatafile.pkl", "r"))  

O/P
ErrorMsg:::
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 44: character maps to <undefined>

Graeme Weatherill

unread,
Jan 18, 2021, 2:34:00 AM1/18/21
to openqua...@googlegroups.com
Yes in Python 3 cPickle is now just pickle. So:

import pickle
db1 = pickle.load(open("path/to/metadatafile.pkl", "rb"))

should work (note the change from "r" to "rb").  Sorry, the GMPE-SMTK manual is not up to date with a couple of the changes made since the SMTK was migrated to Python 3.

Graeme
--
You received this message because you are subscribed to the Google Groups "OpenQuake Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openquake-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openquake-users/834ae81d-4ddd-4c1a-b5e2-c3dbcc98c92cn%40googlegroups.com.


Sonice

unread,
Jan 18, 2021, 6:06:57 AM1/18/21
to OpenQuake Users
Thanks Greame. That worked.
Reply all
Reply to author
Forward
0 new messages