3
votes

I'm tired to import cv and numpy and get errors. I started importing cv and I got this error:

ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "", line 1, in <module>
File "/usr/lib/pymodules/python2.7/cv.py", line 1, in <module>
from cv2.cv import *
ImportError: numpy.core.multiarray failed to import

So I installed numpy on Ubuntu using:

apt-get install python-numpy

So when I import numpy I get:

Traceback (most recent call last):
File "", line 1, in <module>
File "numpy/init.py", line 127, in <module>
raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.

I really need help. I'm using Python 2.7.3 on Ubuntu.

2

2 Answers

4
votes

It's better that use some package management tool such like pip to install numpy. For example,

pip install numpy
8
votes

There is nothing wrong with installing common dependencies using your operating system's package manager, remember using pip means your synaptic updates won't update your Python libraries and pip won't leverage the dependencies already taken care of by aptitude. For python packages with C extensions like numpy and opencv its probably better to use apt-get.

In Ubuntu you can install both dependencies with

sudo apt-get install python-numpy python-opencv

The actual Python error you are getting indicates what is wrong, namely that you are executing from within the numpy source directory, or have a file named numpy.py in your current directory which is confusing things at import time. Try change into an empty directory, start Python import your libraries:

import numpy
import cv

Hope that helps.