Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV 2.4.8: module compiled against API version 9

I just installed the opencv 2.4.8 . I'm using python 2.7. I tried to add the opencv lib to python according to this tutorial. but when I tried to import the opencv I got this error:

import cv2
   RuntimeError: module compiled against API version 9 but this version 
   of numpy is 7

   Traceback (most recent call last):
   File "<pyshell#2>", line 1, in <module>
   import cv2
   ImportError: numpy.core.multiarray failed to import

I updated my scipy and numpy packages to its latest version, but I got the same error. How to fix this problem? I googled it but I found some solutions for Mac OS.

I use Windows 7.

like image 629
Hadi Avatar asked Jan 08 '14 15:01

Hadi


People also ask

Is OpenCV Python and cv2 same?

cv2 is the module import name for opencv-python, "Unofficial pre-built CPU-only OpenCV packages for Python". The traditional OpenCV has many complicated steps involving building the module from scratch, which is unnecessary. I would recommend remaining with the opencv-python library.

Does OpenCV work with Python 2?

Show activity on this post. Python 2.7 is not supported anymore in opencv-python-4.3.

What does the command sudo apt get install OpenCV do?

It is used for a very wide range of applications, including medical image analysis, stitching street view images, surveillance video, detecting and recognizing faces, tracking moving objects, extracting 3D models, and much more.


2 Answers

I got this error too. Finally I figure out I should update numpy to the latest version.

The version of numpy in the tutorial is version 7, but now the team is using version 9 (but numpy team name it 1.8 publicly).

For convenience, check here to download the version I use.

To download the latest version, check here.

like image 106
lesca Avatar answered Oct 23 '22 10:10

lesca


I build OpenCV from source and the problem solved. I used CMake to do that.Don't forget to change the path to the new bin directory in your environment variable.

like image 41
Hadi Avatar answered Oct 23 '22 10:10

Hadi