8

I'm new to the world of opencv and few days ago I tried to install it. I installed everything and moved the cv2 file from opencv to python 2.7. I tired oving both files but with both I'm having an error now I'm trying with file cv2 from folder x86. Whenever I import cv2 I'm having this error :

RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9

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

I tried everything, installing numpy 1.8 reinstalling it, reinstalling other versions of python, adding files to the environmental variables and I'm stuck here for almost week. Also, I have downloaded cygwin64 but after I deleted python 3 (or perhaps it is a coincidence) now it doesn't find any commands like pip install and so on. If someone could help me I would really appreciate it.

Dan Mašek
  • 17,852
  • 6
  • 57
  • 85
  • `import numpy` then `print numpy.__version__`. What do you get? – kabanus Apr 10 '18 at 14:25
  • I get this one 1.8.0 – Artūras Maziliauskas Apr 10 '18 at 14:30
  • This looks very similar to https://stackoverflow.com/questions/33859531/runtimeerror-module-compiled-against-api-version-a-but-this-version-of-numpy-is#39339975. I wonder if you have a few versions somehow. Note the suspect is `numpy`, not `csv2`. Try checking for other versions/upgrading etc. – kabanus Apr 10 '18 at 14:35
  • 3
    This took a bit of time, but I finally found a [table of API version vs numpy version](https://github.com/numpy/numpy/blob/e0f884692f629d931d3673adc8dd6b0938cefa52/numpy/core/setup_common.py#L35). Based on that, I'd say you need numpy 1.10.x or 1.11.x or 1.12.x. – Dan Mašek Apr 10 '18 at 14:39
  • @DanMašek that looks promising, post that as an answer I think. – kabanus Apr 10 '18 at 14:42
  • Thanks, it finally works!!! Thank you guys! – Artūras Maziliauskas Apr 10 '18 at 14:51

2 Answers2

15

Numpy uses a separate version number for the C API. Whenever any changes are made to the C API, this number is increased (irrespective of whether binary compatibility was broken or not). Since the changes are infrequent, there is no 1:1 mapping between Numpy versions and the C API version.

The error message suggests that you have a version of Numpy that provides an older revision of the C-API, compared to what OpenCV was originally built with.

There is a handy table in the source code. Since it was a bit harder to find, let me reproduce it here:

C API Version | Numpy Version
0x00000008 - 1.7.x
0x00000009 - 1.8.x
0x00000009 - 1.9.x
0x0000000a - 1.10.x
0x0000000a - 1.11.x
0x0000000a - 1.12.x
0x0000000b - 1.13.x
0x0000000c - 1.14.x
0x0000000c - 1.15.x
0x0000000d - 1.16.x
0x0000000d - 1.19.x
0x0000000e - 1.20.x
0x0000000e - 1.21.x
0x0000000f - 1.22.x
0x00000010 - 1.23.x
0x00000010 - 1.24.x

Note: Last updated 2022-10-14.

Based on that table, you should upgrade Numpy to any of the following versions: 1.10.x, 1.11.x, 1.12.x

Noumenon
  • 5,099
  • 4
  • 53
  • 73
Dan Mašek
  • 17,852
  • 6
  • 57
  • 85
0

This took a bit of time, but I finally found a table of API version vs numpy version. Based on that, I'd say you need numpy 1.10.x or 1.11.x or 1.12.x. – Dan Mašek