[Solved] numpy.core.multiarray failed to import

I used the following command to know the numpy version I am using

pip show numpy

output shown below

Name: numpy
Version: 1.8.2
Location: /usr/lib/python2.7/dist-packages

However when I am running matplotlib, I got a error as

RuntimeError: module compiled against API version a but this version of numpy is 9
        from matplotlib import pyplot as plt
      File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 27, in <module>
        import matplotlib.colorbar
      File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 32, in <module>
        import matplotlib.artist as martist
      File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 12, in <module>
        from .transforms import Bbox, IdentityTransform, TransformedBbox, 
      File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 39, in <module>
        from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,

I tried to upgrade numpy,

pip install numpy --upgrade

it shows to be installed successfully, but numpy still shows to be 1.8.2 and error continues to exist when running matplotlib.

I thought to uninstall numpy and reinstall it, the system gives the message saying

Not uninstalling numpy at /usr/lib/python2.7/dist-packages, owned by OS

how to solve it ?
any idea about

RuntimeError: module compiled against API version a but this version
of numpy is 9

Solution #1:

How can I upgrade numpy? might be working for you. IN that case it was a path problem:

RuntimeError: module compiled against API version 9 but this version of numpy is 6
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import 


Check the path

import numpy
print numpy.__path__

and manually delete it using rm

Respondent: user824624

Solution #2:

I also had the same problem until I came across this Issue on Pytorch github repository. This command worked perfectly for me:

pip install numpy -I

It is also mentioned there that pip install numpy --upgrade is not working(don’t know why). You can check the above mentioned link.

Respondent: cattt84

Solution #3:

The answer is probably simple.
Just add
import numpy.core.multiarray
before the
import cv2
It worked fine for me.

Respondent: Mukul

Solution #4:

I had a similar problem with numpy when running torch. I tried uninstalling numpy and installing it using -U but it didn’t work. After some search, I found this link and it solved my problem. It says you should change your numpy version.

pip uninstall numpy
pip install numpy==1.19.3
Respondent: DIVYA RATHOD

Solution #5:

Installing the previous version of NumPy, 1.19.3 should fix this. python -m pip install numpy==1.19.3

Respondent: Soroush Karimi

Solution #6:

My problem is solved using the old version of numpy. The solution is to use numpy 1.19.3.

pip install numpy==1.19.3


Respondent: Prasoon Singh

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy