AttributeError: Can't get attribute '_unpickle_block'

Question:

While using:

with open("data_file.pickle", "rb") as pfile:
     raw_data = pickle.load(pfile)  

I get the error:

AttributeError: Can't get attribute '_unpickle_block' on <module 'pandas._libs.internals' from '/opt/conda/lib/python3.8/site-packages/pandas/_libs/internals.cpython-38-x86_64-linux-gnu.so'>

Another answer to a similar question suggests checking the version of pickle I am using. It is the same on my machine, where I developed the code and on server, where I am running the code. I have searched everywhere with no answers. Please help.

Asked By: No-Time-To-Day

||

Answers:

I don’t think the problem is pickle module but Pandas version. Your file was probably created with an older version of Pandas. Now you use a newer version, pickle can’t "deserialize" the object because the API change.

Try to downgrade your Pandas version and reload file. You can also try to use pd.read_pickle.

Answered By: Corralien

In my case I had to upgrade instead of downgrade the Pandas version. Just make sure they match. Some tips for future readers:

Ask the version with:

import pandas as pd
pd.__version__

And change the version with (replace with your own version)

%pip install pandas==1.4.1
Answered By: Tessa I

I got this error when using vscode and .net interactive notebooks extension. It got resolved when I updated pandas AND restarted the notebook.

Answered By: BSalita

all you have to do is downgrade your sklearn version to 1.0.2

doesn’t work?
make sure the version you had used in your code and env as same.

that’ll work.

happy coding!!

Answered By: Eswar

Just change the read function from (pickle.load(f)) to (pd.read_pickle(f)) without changing anything in the versions

# from this :

with open('Data.pkl', 'rb') as f:
     t = pickle.load(f)

# to this:
import pandas as pd 
with open('Data.pkl', 'rb') as f:
      t = pd.read_pickle(f)

it is solve the problem for me.

Answered By: Mostafa Alheyaly
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.