Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install opencv with conda

This question is different from "How do I install Python OpenCV through Conda?" because that question was asked more than 5 years ago, when all packages had different versions. I tried ALL answers to that question, and neither worked. See the text of question for details.

How to install opencv with conda now, in July 2019? On a freshly installed anaconda, I did conda update conda (succesfully) then tried the following:

(base) C:\Users\mlearning>python
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
>>> import cv
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv'

(base) C:\Users\mlearning>conda install -c menpo opencv3
Collecting package metadata (repodata.json): done
Solving environment: (goes into infinite loop, after 10 minutes I pressed ^C)

(base) C:\Users\mlearning>conda install opencv
Collecting package metadata (repodata.json): done
Solving environment: failed
Initial quick solve with frozen env failed.  Unfreezing env and trying again.
Solving environment: failed

UnsatisfiableError: The following specifications were found to be incompatible with each other:

Package zipp conflicts for:
importlib_metadata -> zipp[version='>=0.3.2']
path.py -> importlib_metadata[version='>=0.5'] -> zipp[version='>=0.3.2']
anaconda==2019.03=py37_0 -> importlib_metadata==0.8=py37_0 -> zipp[version='>=0.3.2']
zipp
Package importlib_metadata conflicts for:
anaconda==2019.03=py37_0 -> importlib_metadata==0.8=py37_0
path.py -> importlib_metadata[version='>=0.5']
Package hdf5 conflicts for:
anaconda==2019.03=py37_0 -> h5py==2.9.0=py37h5e291fa_0 -> hdf5[version='>=1.10.4,<1.10.5.0a0']
hdf5
opencv -> hdf5[version='>=1.10.2,<1.10.3.0a0,>=1.8.18,<1.8.19.0a0,>=1.8.20,<1.9.0a0']
h5py -> hdf5[version='>=1.10.1,<1.10.2.0a0,>=1.10.2,<1.10.3.0a0,>=1.10.4,<1.10.5.0a0,>=1.8.18,<1.9.0a0']
pytables -> hdf5[version='>=1.10.1,<1.10.2.0a0,>=1.8.18,<1.8.19.0a0,>=1.8.18,<1.9.0a0']
Package mkl-service conflicts for:
mkl-service
anaconda==2019.03=py37_0 -> mkl-service==1.1.2=py37hb782905_5

(base) C:\Users\mlearning>conda install -c conda-forge opencv
Collecting package metadata (repodata.json): done
Solving environment: failed
Initial quick solve with frozen env failed.  Unfreezing env and trying again.
Solving environment: failed

UnsatisfiableError: The following specifications were found to be incompatible with each other:

Package hdf5 conflicts for:
anaconda==2019.03=py37_0 -> hdf5==1.10.4=h7ebc959_0
h5py -> hdf5[version='1.10.1,1.8.17|1.8.17.*,1.8.18|1.8.18.*,>=1.10.2,<1.10.3.0a0,>=1.10.3,<1.10.4.0a0,>=1.8.20,<1.9.0a0']
pytables -> hdf5[version='1.8.18|1.8.18.*,>=1.10.4,<1.10.5.0a0,>=1.8.18,<1.8.19.0a0,>=1.8.18,<1.9.0a0']
hdf5
Package mkl-service conflicts for:
mkl-service
Package importlib_metadata conflicts for:
importlib_metadata
path.py -> importlib_metadata[version='>=0.5']
like image 337
user31264 Avatar asked Jul 24 '19 15:07

user31264


1 Answers

I have had countless problems with installing opencv with conda This is my approach, create an env if you don't already have one

conda create -n py36 python=3.6
conda activate py36

Install opencv with pip NOT conda

pip install opencv-python

If your still having an issue, uninstall opencv, update ffmpeg

conda install -c conda-forge ffmpeg 

then rerun pip

UPDATE 2020

install pip with you env activate

conda install pip

verify pip is in your env

whereis
pip: /path/anaconda3/envs/your_env/bin/pip

Install opencv with pip

~/anaconda3/envs/your_env/bin/pip3 install opencv-python

like image 157
Kenan Avatar answered Sep 25 '22 12:09

Kenan