22

I have such a problem

(face_det) user@pc:~$ python3
Python 3.5.3 (default, Apr 22 2017, 00:00:00) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'cv2

I don't have it on python2:

(face_det) user@pc:~$ python2
Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import cv2
>>> 

In spite of the fact, that I have opencv (I've also tryed to remove it and install then):

(face_det) user@pc:~$ pip3 install opencv
Requirement already satisfied: opencv in ./.virtualenvs/face_det/lib/python3.5/site-packages
(face_det) user@pc:~$ conda install opencv
Fetching package metadata .........
Solving package specifications: .

# All requested packages already installed.
# packages in environment at /home/pc/anaconda3:
#
opencv                    3.2.0               np112py27_0    conda-forge
Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Firsttry
  • 319
  • 1
  • 3
  • 6
  • There appears to be an [open issue](https://github.com/opencv/opencv/issues/8039) on their GitHub about this and some suggestions to fix it. – roganjosh Aug 11 '17 at 21:02
  • is that a duplicate: https://stackoverflow.com/questions/19876079/opencv-cannot-find-module-cv2 – Jean-François Fabre Aug 11 '17 at 21:03
  • @Jean-FrançoisFabre I think they're referencing different issues. I'm not sure it's safe to dupe, the issue I linked to suggest that there may be dependency problems. – roganjosh Aug 11 '17 at 21:09
  • 2
    Ok, not abusing my gold badge powers and not closing as a duplicate. Note that this problem never gets old :) – Jean-François Fabre Aug 11 '17 at 21:11
  • @Jean-FrançoisFabre it is of course your prerogative :P But on this one, I think there may be a genuine conflict somewhere. – roganjosh Aug 11 '17 at 21:13

6 Answers6

43

Try

pip3 install opencv-python

to get the cv2. I'm not sure when opencv-python became available. I'd been building opencv by hand, but when I looked a few weeks ago, there it was. I'm using cv2 with Python3 in a VM that's running ubuntu/trusty64.

Dave W. Smith
  • 24,318
  • 4
  • 40
  • 46
6

Try

sudo python3.5 -m pip install opencv-python

It worked for me

Sunil Sharma
  • 249
  • 3
  • 8
2

On Windows you can try this:

python3 -m pip install opencv-python
gmauch
  • 1,316
  • 4
  • 25
  • 39
0

I think you're on Linux judging by pc:~$

Try installing from the following link:

http://docs.opencv.org/3.0-beta/doc/tutorials/introduction/linux_install/linux_install.html

It worked for me, hope the same for you!

Eren Tantekin
  • 1,461
  • 14
  • 24
Xmaddy
  • 11
  • 3
0

Your conda openCV is installed for use by your home python2.7. Your opencv installed via pip3 is for use in your face_det virtual environment. It doesn't look like you're in that virtual environment when you opened python3 in the first code block. Try

source activate face_det
python3
import cv2
pale bone
  • 1,746
  • 2
  • 19
  • 26
0

I had a similar problem and the same error. In my case, I was using PyCharm. The problem was that the project's interpreter was pointing to a different installation of Python.

In my system, I had four versions of python (eg. python3 installed in a python36 folder, another python in an anaconda3 folder and others). In my PyCharm project, when I examined my settings (under File->Settings->Project:xxxx ->Project interpreter), I found that they were pointing to the interpreter in the anaconda3 folder.

However, my default pip installed the opencv-python module under the python36 folder. Therefore, I just had to change the project interpreter to point to the python installed in python36 folder and it worked.

If you would like to keep using Anaconda3 then you have to browse to the anaconda3 folder and run pip install opencv-python in that folder.

ScottMcC
  • 4,094
  • 1
  • 27
  • 35
redcode
  • 71
  • 1
  • 1