ImportError: No module named 'cv2' Python3

Firsttry picture Firsttry · Aug 11, 2017 · Viewed 62.6k times · Source

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

Answer

Dave W. Smith picture Dave W. Smith · Aug 19, 2017

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.