We often use numpy.load() function to load an object from a file. However we may get this error: ValueError: Object arrays cannot be loaded when allow_pickle=False. In this tutorial, we will introduce how to fix it.
Look at this example below:
import numpy as np obj = np.load(file)
Here file is a npy file, which saved an object.
Run this code, we get this error:
How to fix this ValueError?
It is simple to fix this error. Here are two methods.
Method 1: install numpy 1.16.2 version.
Because numpy version > 1.16.2, all_pickle = False defaultly.
You can install numpy like:
pip install --force-reinstall numpy==1.16.2
Method 2: set allow_pickle=True when using np.load()
obj = np.load(file, allow_pickle=True)
Then you will find this error is fixed.