Anaconda: cannot import cv2 even though opencv is installed (how to install opencv3 for python3)

回眸只為那壹抹淺笑 提交于 2019-12-21 07:55:52

问题


I have anaconda (version: conda 4.2.9, python3) installed and am trying to do import cv2 when I get the following error:

ImportError: No module named 'cv2'

With conda search cv2 I get this:

opencv 2.4.2 np15py26_0 defaults
2.4.2 np15py27_0 defaults
2.4.2 np16py26_0 defaults
2.4.2 np16py27_0 defaults
2.4.2 np17py26_0 defaults
2.4.2 np17py27_0 defaults
2.4.2 np15py26_1 defaults
2.4.2 np15py27_1 defaults
2.4.2 np16py26_1 defaults
2.4.2 np16py27_1 defaults
2.4.2 np17py26_1 defaults
2.4.2 np17py27_1 defaults
2.4.6 np16py26_0 defaults
2.4.6 np16py27_0 defaults
2.4.6 np17py26_0 defaults
2.4.6 np17py27_0 defaults
2.4.6 np18py26_0 defaults
2.4.6 np18py27_0 defaults
2.4.9 np18py27_0 defaults
2.4.10 np19py26_0 defaults
2.4.10 np19py27_0 defaults
2.4.10 np110py27_1 defaults
2.4.10 np19py26_1 defaults
2.4.10 np19py27_1 defaults

What do I need to do to be able to import the cv2 module? Thanks!

PS: I am using Ubuntu 16.04


回答1:


opencv is not compatible with python 3. I had to install opencv3 for python 3. The marked answer in how could we install opencv on anaconda? explains how to install opencv(3) for anaconda:

Run the following command:

conda install -c https://conda.binstar.org/menpo opencv

I realized that opencv3 is also available now, run the following command:

conda install -c https://conda.binstar.org/menpo opencv3

Edit on Aug 18, 2016: You may like to add the "menpo" channel permanently by:

conda config --add channels menpo

And then opencv can be installed by:

conda install opencv (or opencv3)

Edit on Aug 14, 2017: "clinicalgraphics" channel provides relatively newer vtk version for very recent python3

conda install -c clinicalgraphics vtk




回答2:


You can try

conda install -c menpo opencv=3



回答3:


Can be too late, but i'm going to help. I had the same problem, i've created my conda env and installed everything i'll need, but when i've tryed to import cv2, i've received a message 'no module named cv2'. I've tryed install again and i've done the Linda's tips and haven't worked. So, i've seen that my conda env haven't had the cv2 installed. If it happened you, you just copy your cv2 folder to "miniconda'X'/envs/yourEnv/lib/python'X.X'/site-packages/" that will work. At least have worked to me




回答4:


The file may be not installed properly, please see the bellow the instructions.

Run the following commands

Sudo apt-get update
Sudo apt-get upgrade

then

pip install opencv-python

check-in your jupyter notebook

import cv2
print cv2.__version__

This may solve the issue.




回答5:


opencv isn't in the default conda installation repo, so you will need to install it from the channel.

conda install --channel https://conda.anaconda.org/anaconda opencv



来源:https://stackoverflow.com/questions/39977808/anaconda-cannot-import-cv2-even-though-opencv-is-installed-how-to-install-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!