0

I am trying to use opencv but whenever I try to import the package I get the

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

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

error. So I did some research and found the question with an identical problem to my own, but the answers provided there all cause a syntax error for me in the python command line. This is the most common answer I've seen that doesn't work for me:

pip install -U numpy 

And several variations of that that all result in syntax errors. I have python 2.7.5 and did have numpy 1.9.1, but I uninstalled it when I was trying to figure out the problem, so I currently have numpy 1.7.1 downloaded. I asked for help with this in the comments section of my previous question, but a bunch of people marked my question as a duplicate of some other question (that doesn't work for me) and now I'm not getting much help. That said, if anyone knows how to solve my problem, that would be much appreciated.

ΦXocę 웃 Пepeúpa ツ
  • 43,054
  • 16
  • 58
  • 83
  • 1
    Are you just entering them into the repl? Those are meant to be used in cmd/bash/terminal. – internet_user Nov 20 '17 at 21:48
  • This is going to be very environmental and hard for anyone to help you with. You should pay attention to the syntax error from that pip command you don't share with us. –  Nov 20 '17 at 21:49
  • @pycoder I'm entering them into the python command line. I don't know if that's the same thing. – amycarleton Nov 20 '17 at 21:50
  • @jdv unfortunately the error is pretty vague. This is the code: `>>> pip install -U numpy File "", line 1 pip install -U numpy ^ SyntaxError: invalid syntax` – amycarleton Nov 20 '17 at 21:52
  • @pycoder Yes I think so. It seems that anything I put there results in a syntax error; I tried copying one of the commands from that link and pasting it into the command line and it gave me the same kind of syntax error. – amycarleton Nov 20 '17 at 21:55

1 Answers1

0

Based on the comments on your question and your own replies, I think that the problem is you are trying to enter the command into Python repl, when you should actually enter the command into the terminal/bash environment.

If you are on Mac, open the Terminal application, then without doing anything else, type the command in. It should look something like this:

amycarleton-MacBook-Pro:~ Amy$ pip install -U numpy

Then enter the command. This should help you update to the correct version.

If you are using other OS, do the same thing, open the terminal/bash equivalent application, then enter the command without invoking Python.

The error was raised because you entered the command into a Python environment, which the syntax is invalid in Python.

yanxun
  • 426
  • 2
  • 8