1
votes

I'm running a jupyter notebook in google datalab running python 3. I'd like to use cv2 but am unable to import the module.

I was able to install opencv using:

!pip install opencv-python

I got the following confirmation:

Collecting opencv-python Using cached opencv_python-3.4.0.12-cp27-cp27mu-manylinux1_x86_64.whl

Requirement already satisfied: numpy>=1.11.1 in /usr/local/lib/python2.7/dist-packages (from opencv-python)

Installing collected packages: opencv-python

Successfully installed opencv-python-3.4.0.12

When I try to "import cv2" I get the following error:

importError Traceback (most recent call last) in () ----> 1 import cv2

ImportError: No module named 'cv2'

When I list the modules using

help("modules") 

neither opencv or cv2 are shown.

Any help would be greatly appreciated.

3

3 Answers

2
votes

If the above answers haven't solved your problem, try:

!pip3 install opencv-python

In Datalab 'pip' is 'pip2', so for python 3 installs you have to use pip3.

1
votes

It's opencv-python, not python-opencv.

Use this command to install cv2.

!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python

Shows cv2 version from my colab notebook

Shows cv2 version from my colab notebook

BTW, if you still have some problem, try to Restart Runtime.

0
votes

I had the same issue. It worked when I ran

!apt-get update

before the install command. You might have to run apt-get install with the --allow-unauthenticated flag though.