简体   繁体   中英

Can't install opencv or import cv2 in google datalab

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.

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.

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

从我的colab笔记本显示cv2版本

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM