Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python read pickle protocol 4 error: STACK_GLOBAL requires str

In Python 3.7.5, ubuntu 18.04, pickle read gives error,

pickle version 4

Sample code:

import pickle as pkl
file = open("sample.pkl", "rb")
data = pkl.load(file)

Error:

UnpicklingError Traceback (most recent call last) in
----> 1 data = pickle.load(file) UnpicklingError: STACK_GLOBAL requires str

Reading from same file object solves problem.

Reading using pandas also gives same problem

like image 230
Elbek Avatar asked Nov 20 '19 08:11

Elbek


1 Answers

I also has this error turned out I was opening a numpy file with pickle. ;)

like image 67
Kartik Avatar answered Nov 03 '22 11:11

Kartik