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

RuntimeError: module compiled against API version a but this version of numpy is 9 is an error which occurs when there is a incompatibility issue or if the numpy installation is faulty.

In this article I am going to help you solve this error and understand the root of the problem, also I am presenting other possible solutions that may work if the main solution does not work for you.

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

The problem happens when there is an error which occurs when there is a incompatibility issue or if the numpy installation is faulty.

The error message should look like the error in the example bellow. Make sure your error message is very similar to the one bellow.

Solving RuntimeError module compiled against API version a but this version of numpy is 9-problem-banner

Bellow we will take care of the error using multiple possible solutions according to your needs.

Solution 1 : move the numpy directory

The First solution is simple, you should move the numpy directory.

First, you should know where the directory is. to do that. You should start by importing numping and checking the path.

To import numpy

                                                                       #
# use this to import numpy
import numpy
                                                                       #

Check the full path.

                                                                       #
# use this to check the full path
print numpy.__path__
                                                                       #

Move the directory of the numpy.

Solving RuntimeError module compiled against API version a but this version of numpy is 9-problem-banner-1

This solution should work easily, if not you can follow the instructions bellow to upgrade numpy.

Solution 2 : upgrade numpy.

The second solution is to upgrade numpy.

Use the command bellow in order to upgrade numpy to the most recent version possible.

                                                                       #
# Use the command bellow in order to upgrade numpy
pip install numpy --upgrade
                                                                       #

If the command above does not work, try using the following command.

                                                                       #
# try using the following command If the command above does not work
sudo pip install numpy --upgrade --ignore-installed
                                                                       #

This solution should be enough, if that is not the case check the solution using brew bellow.

Solution 3 : use brew to install both python and opencv.

The third solution is to use brew to install both python and opencv. The install will be in /usr/local.

First, start by installing python using brew

                                                                       #
# start by installing python using brew
brew install python
                                                                       #

The second is to again use brew in order to install homebrew/science.

                                                                       #
# use brew in order to install homebrew/science.
brew tap homebrew/science
                                                                       #

Finally, we can use brew to install opencv

                                                                       #
# use this to install opencv
brew install opencv
                                                                       #

Python will be running from /usr/local/bin/python.

These commands should be enough to solve your problem.

If the solutions above helped you, consider supporting us on Kofi, any help is appreciated.

Summing-up

This is the end of our article, I hope this helped you solve the error or at least showed you the way. You can donate to our Kofi account but you do not Have to. Keep coding and cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/