Google colabのpandasでError: Unsupported Pickle Protocol 5

ローカルマシンで作成したpickleをColabで読み込もうとしたときに表題のエラー。

# ローカルマシン
df.to_pickle("df.pickle")

# Colab
df = pd.read_pickle("df.pickle")

Error: Unsupported Pickle Protocol 5

pickle5はpython3.8から導入されたらしい。

ローカルマシンは3.8.4だったので、Colabはpickle5が導入される前のバージョンなのかも?

PEP 574 – Pickle protocol 5 with out-of-band data | peps.python.org
Python Enhancement Proposals (PEPs)

!python -V
Python 3.7.10

Colabでは3.7で、pickle5が導入される前のPythonバージョンになっていた。

別途 pickle5 のモジュールをColabにインストールする。

pickle5
Backport of the pickle 5 protocol (PEP 574) and other pickle changes
!pip install pickle5

あとはimportしてロードすればOK。

import pickle5

with open("df.pickle", "rb") as f:
    df = pickle5.load(f)


df.head()

参考

Python 3.7 Error: Unsupported Pickle Protocol 5
I'm trying to restore a pickled config file from RLLib (json didn't work as shown in this post), and getting the followi...

コメント

タイトルとURLをコピーしました