+1 vote
in Programming Languages by (66.7k points)

When I try to load a saved pickle file using "pickle.load()", it throws the following error: 

ModuleNotFoundError: No module named 'numpy._core.numeric'

I had saved the pickle file using protocol 5. It seems a incompatibility issue for me. How can I fix it?

1 Answer

+1 vote
by (366k points)
selected by
 
Best answer

This is a NumPy/Pickle compatibility issue, not a bug in your logic. The pickle file was likely created with a different NumPy version. During pickle.load(), Python is trying to import the old/new module path. To fix the error, you can try the following code:

import sys

import numpy.core

import numpy.core.numeric

sys.modules["numpy._core"] = numpy.core

sys.modules["numpy._core.numeric"] = numpy.core.numeric

with open(file_path, "rb") as f:

    f_data = pickle.load(f)

Related questions


...