Install opencv with conda
Solution 1
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
Solution 2
Create a complete new environment and let conda deal with compatibilities:
conda create -n cv -c conda-forge opencv matplotlib
This will create a new environment named "cv" with python, opencv and matplotlib.
Today (Out. 11th, 2019) it installed:
- Python 3.7.3
- OpenCV 4.1.1
- MatPlotLib 3.1.1
- Numpy 1.17.2
- ... and all other dependencies.
Solution 3
directly run
pip install opencv-python
on spyder instead
Solution 4
I faced similar problem (only hdf5 conflicted). The reason is using incompatible version python.
How about creating new python3.6 environment before installing openCV? You can create new environment like this.
$ conda create -n py36 python=3.6
In addition you should also type this command to activate.
$ activate py36
Solution 5
The easiest way is:
conda install pip
pip install opencv-python
Have fun!
user31264
Updated on July 09, 2022Comments
-
user31264 almost 2 years
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']
-
merv almost 5 yearsWhy not just create the env from the start around the fact that OpenCV is what you want to install? I.e.,
conda create -n opencv_env opencv
. If you want Python 3.6 you can specify that as well:conda create -n opencv_env opencv python=3.6
-
ashiba almost 5 years@merv There is no paticular reason. If I had to say, I didn't know the conda command's notation.
-
user31264 about 4 yearsHad you read my post? Among other things, I did exactly this, and it didn't work.
-
AMC about 4 yearsI have had countless problems with installing opencv with conda Can you elaborate? Using pip for this should really be a last resort.
-
AMC about 4 yearsHow about creating new python3.6 environment before installing openCV? You should be using a separate environment for each project anyway.
-
AMC about 4 yearsCan you elaborate on the issue you were having?
-
Peteris almost 4 yearsDoes not work at June 2020; results in 'ImportError: DLL load failed: The specified module could not be found'.