Anaconda 2020.11 issue with OpenCV

solution of issue for opencv and latest anaconda with python3.8

Vikash Kumar

3 minute read

Recently I installed Anaconda 2020.11 on my Mac machine. When I tried to installed opencv package, it showed errors. Below is the error excrept:

$ conda install -c conda-forge opencv
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: -
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - opencv -> python[version='>=2.7,<2.8.0a0|>=3.5,<3.6.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0']

Your python: python=3.8

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

Above error suggested that opencv package in the current repository is only supported with python version <3.8.0a0. After googling for a bit, I found many different solution but none of them worked in my case. My conda details:

$ conda info
     active environment : pandas
    active env location : /Users/user-abc/anaconda3/envs/pandas
            shell level : 1
       user config file : /Users/user-abc/.condarc
 populated config files : /Users/user-abc/.condarc
          conda version : 4.9.2
    conda-build version : 3.20.5
         python version : 3.8.5.final.0
       virtual packages : __osx=10.15.7=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /Users/user-abc/anaconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /Users/user-abc/anaconda3/pkgs
                          /Users/user-abc/.conda/pkgs
       envs directories : /Users/user-abc/anaconda3/envs
                          /Users/user-abc/.conda/envs
               platform : osx-64
             user-agent : conda/4.9.2 requests/2.24.0 CPython/3.8.5 Darwin/19.6.0 OSX/10.15.7
                UID:GID : 502:20
             netrc file : None
           offline mode : False

So, I started searching for availble python versions of conda:

$ conda search python
Loading channels: done
# Name                       Version           Build  Channel
python                        2.7.13     h32f5f24_13  pkgs/main
python                        2.7.13     h89fad4f_16  pkgs/main
python                        2.7.13     hdada7c8_15  pkgs/main
...
python                         3.7.4      h359304d_1  pkgs/main
python                         3.7.5      h359304d_0  pkgs/main
python                         3.7.6      h359304d_2  pkgs/main
python                         3.7.7 hc70fcce_0_cpython  pkgs/main
python                         3.7.7      hf48f09d_4  pkgs/main
python                         3.7.7 hfe9666f_0_cpython  pkgs/main
python                         3.7.9      h26836e1_0  pkgs/main
python                         3.8.0      h359304d_0  pkgs/main
python                         3.8.0      h359304d_1  pkgs/main
python                         3.8.0      h359304d_2  pkgs/main
python                         3.8.1      h359304d_1  pkgs/main
python                         3.8.2      hc70fcce_0  pkgs/main
python                         3.8.2     hf48f09d_13  pkgs/main
python                         3.8.2      hfe9666f_0  pkgs/main
python                         3.8.3      h26836e1_1  pkgs/main
python                         3.8.3      h26836e1_2  pkgs/main
python                         3.8.5      h26836e1_0  pkgs/main
python                         3.8.5      h26836e1_1  pkgs/main
python                         3.9.0      h88f2d9e_1  pkgs/main
python                         3.9.0      h88f2d9e_2  pkgs/main
python                         3.9.1      h88f2d9e_2  pkgs/main

Then, searched for available opencv package.

$ conda search opencv
Loading channels: done
# Name                       Version           Build  Channel
opencv                         3.3.1  py27h2dac755_0  pkgs/main
opencv                         3.3.1  py27h4e978fd_0  pkgs/main
opencv                         3.3.1  py27h60a5f38_1  pkgs/main
...
opencv                         3.4.2  py36h40b0b35_1  pkgs/main
opencv                         3.4.2  py36h6fd60c2_0  pkgs/main
opencv                         3.4.2  py36h6fd60c2_1  pkgs/main
opencv                         3.4.2  py37h40b0b35_0  pkgs/main
opencv                         3.4.2  py37h40b0b35_1  pkgs/main
opencv                         3.4.2  py37h6fd60c2_0  pkgs/main
opencv                         3.4.2  py37h6fd60c2_1  pkgs/main

Look at the last row. Check py37h6fd60c2_1

opencv                         3.4.2  py37h6fd60c2_1  pkgs/main

This confirmed that the latest opencv package is built with py37 packages and hence it is not installable with python3.8.

Now the most tempting thing to do is to downgrade python version.

$ conda install python=3.7

Wait, this is going to take lot of time and in last will show multiple conflicts which is not easy to resolve.

So, what is the simple solution ? Virtual environment comes to rescue. By default, anaconda runs in environment name “base”. If you are familiar with python, we have package called virtualenv to create virtual environment. The same thing we can do here with conda.

Steps:

conda create -n myenv python=3.7	# This will create a virtual environment named myenv with python3.7
conda activate myenv
conda install -c conda-forge opencv

That’s it you are ready to use opencv package

comments powered by Disqus