Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't install OpenCV3 on Anaconda3 python3.6 on macOS

I'm trying to install OpenCV 3.2.0 on Anaconda3 python 3.6 on macOS 10.11.6 but I can't find a way. My Anaconda3 has python 3.5.2 installed but if I create a new virtual environment using

$ conda create -n myvenv python  
then it downloads and installs python 3.6 on the new myvenv. A simple search  
$ conda search opencv
opencv                       2.4.8                np17py27_2  defaults 

while opencv3 yields no results

$ conda search opencv3
NoPackagesFoundError: Package missing in current osx-64 channels: 
  - opencv3

Installing menpo opencv3 build gives following conflict:

$ conda install -c menpo opencv3
Fetching package metadata ...........
Solving package specifications: .
UnsatisfiableError: The following specifications were found to be in conflict:
  - opencv3 -> python 2.7* -> openssl 1.0.1*
  - python 3.6*
Use "conda info <package>" to see the dependencies for each package.

I tried to install using homebrew but linking it with Anaconda3 python3 seems difficult:

$ brew install eigen tbb
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/eigen-3.3.1.el_capitan.bottle.tar.gz
100.0%
==> Pouring eigen-3.3.1.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/eigen/3.3.1: 486 files, 6.4M
==> Downloading https://homebrew.bintray.com/bottles/tbb-4.4-20161128.el_capitan.bottle.tar.gz
100.0%
==> Pouring tbb-4.4-20161128.el_capitan.bottle.tar.gz
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
  mkdir -p /Users/<username>/.local/lib/python3.5/site-packages
  echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/<username>/.local/lib/python3.5/site-packages/homebrew.pth
==> Summary
🍺  /usr/local/Cellar/tbb/4.4-20161128: 119 files, 1.9M

More info

$ conda info
Current conda install:
               platform : osx-64
          conda version : 4.3.8
       conda is private : False
      conda-env version : 4.3.8
    conda-build version : 2.0.2
         python version : 3.5.2.final.0
       requests version : 2.12.4
       root environment : /Users/<username>/anaconda3  (writable)
    default environment : /Users/<username>/anaconda3/envs/lesvenv
       envs directories : /Users/<username>/anaconda3/envs
          package cache : /Users/<username>/anaconda3/pkgs
           channel URLs : https://repo.continuum.io/pkgs/free/osx-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/osx-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/osx-64
                          https://repo.continuum.io/pkgs/pro/noarch
            config file : None
           offline mode : False
             user-agent : conda/4.3.8 requests/2.12.4 CPython/3.5.2 Darwin/15.6.0 OSX/10.11.6
                UID:GID : 502:20

while coda list is:

$ conda list
packages in environment at /Users/<username>/anaconda3/envs/lesvenv:
anaconda-client           1.6.0                    py36_0
clyent                    1.2.2                    py36_0
mkl                       2017.0.1                      0
numpy                     1.11.3                   py36_0
openssl                   1.0.2j                        0
pip                       9.0.1                    py36_1
python                    3.6.0                         0
python-dateutil           2.6.0                    py36_0
pytz                      2016.10                  py36_0
pyyaml                    3.12                     py36_0
readline                  6.2                           2
requests                  2.12.4                   py36_0
setuptools                27.2.0                   py36_0
six                       1.10.0                   py36_0
sqlite                    3.13.0                        0
tk                        8.5.18                        0
wheel                     0.29.0                   py36_0
xz                        5.2.2                         1
yaml                      0.1.6                         0
zlib                      1.2.8                         3

My anaconda is: /Users/<username>/anaconda3/bin/anaconda
My python 3.5.2 is: /Users/<username>/anaconda3/bin/python
My conda myvenv python 3.6 is: /Users/<username>/anaconda3/envs/myvenv/bin/python

like image 700
Shah-G Avatar asked Jan 26 '17 12:01

Shah-G


2 Answers

This answer is now outdated (unless for some reason you wanted to use an older version of OpenCV) - please see this answer

The above correct answer did not work for me.

Ended up lowering the version of python until this is fixed.

conda install python=3.5 conda install -c menpo opencv3

I know this is not a permanent fix, but this works for me and you get to stay within the conda environment without doing much.

The issue is currently referenced here: https://github.com/conda/conda/issues/2448

Hope this helps!

like image 142
Viv Avatar answered Oct 27 '22 14:10

Viv


Since you are using a newer version of python3, you would probably have to build opencv from the recipe yourself, which is available at https://github.com/conda-forge/opencv-feedstock

Another option is to have the specific version of python3 in your new environment by creating it like this:

(root) osx:Downloads nwani$ conda list | grep python
python                    3.6.0                         0 
(root) osx:Downloads nwani$ conda create -yn opencvtest python=3.5.2
(root) osx:Downloads nwani$ source activate opencvtest
(opencvtest) osx:Downloads nwani$ conda list | grep python
python                    3.5.2                         0

The version 3.1.0 builds of opencv are available on the conda-forge channel:

(root) osx:Downloads nwani$ conda search -c conda-forge --spec 'opencv=3*'
Fetching package metadata .........
opencv                       3.1.0               np110py27_0  conda-forge     
                             3.1.0               np110py34_0  conda-forge     
                             3.1.0               np110py35_0  conda-forge     
                             3.1.0               np111py27_0  conda-forge     
                             3.1.0               np111py34_0  conda-forge     
                             3.1.0               np111py35_0  conda-forge     
                             3.1.0               np110py27_1  conda-forge     
                             3.1.0               np110py34_1  conda-forge     
                             3.1.0               np110py35_1  conda-forge     
                             3.1.0               np111py27_1  conda-forge     
                             3.1.0               np111py34_1  conda-forge     
                             3.1.0               np111py35_1  conda-forge

You can install it like this:

(opencvtest) osx:Downloads nwani$ conda install -y -c conda-forge opencv 
(opencvtest) osx:Downloads nwani$ conda list | grep -e python -e opencv
# packages in environment at /Users/nwani/Downloads/m3/envs/opencvtest:
opencv                    3.1.0               np111py35_1    conda-forge
python                    3.5.2                         0  
like image 44
Nehal J Wani Avatar answered Oct 27 '22 13:10

Nehal J Wani