web-dev-qa-db-fra.com

Impossible d'installer OpenCV3 sur Anaconda3 python3.6 sur macOS

J'essaie d'installer OpenCV 3.2.0 sur Anaconda3 Python 3.6 sur macOS 10.11.6, mais je ne trouve aucun moyen . Mon Anaconda3 a installé Python 3.5.2, mais je crée un nouvel environnement virtuel à l'aide de 

$ 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 

alors qu'opencv3 ne donne aucun résultat 

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

L'installation de menpo opencv3 build donne les conflits suivants: 

$ 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.

J'ai essayé d'installer en utilisant homebrew mais l'associer à Anaconda3 python3 semble difficile: 

$ 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

Plus d'informations 

$ 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

tandis que la liste de coda est: 

$ 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

Mon anaconda est: /Users/<username>/anaconda3/bin/anaconda
Mon python 3.5.2 est: /Users/<username>/anaconda3/bin/python
Mon condy myvenv python 3.6 est: /Users/<username>/anaconda3/envs/myvenv/bin/python

17
Shah Ismail

Puisque vous utilisez une version plus récente de python3, vous devrez probablement créer vous-même une solution à partir de la recette, disponible à l’adresse https://github.com/conda-forge/opencv-feedstock

Une autre option consiste à avoir la version spécifique de python3 dans votre nouvel environnement en la créant comme suit:

(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

La version 3.1.0 d’opencv est disponible sur le canal conda-forge:

(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

Vous pouvez l'installer comme ceci:

(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  
15
Nehal J Wani

Cette réponse est maintenant obsolète (à moins que pour une raison quelconque vous vouliez utiliser une version plus ancienne d'OpenCV) - veuillez voir cette réponse

La réponse correcte ci-dessus n'a pas fonctionné pour moi.

Nous avons fini par abaisser la version de Python jusqu'à ce que cela soit corrigé.

conda install python=3.5 conda install -c menpo opencv3

Je sais que ce n'est pas une solution permanente, mais cela fonctionne pour moi et vous devez rester dans l'environnement conda sans faire grand chose.

Le numéro est actuellement référencé ici: https://github.com/conda/conda/issues/2448

J'espère que cela t'aides!

22
Viv

J'ai trouvé que la solution acceptée ne fonctionne pas sur Python 3.6 avec Anaconda. 

Donc, pour installer opencv manuellement et continuer à le faire fonctionner avec conda:

$ cd ~
$ git clone https://github.com/opencv/opencv
$ git clone https://github.com/opencv/opencv_contrib
$ cd ~/opencv
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D PYTHON3_LIBRARY=/Users/yourusername/anaconda3/lib/libpython3.6m.dylib \
    -D PYTHON3_INCLUDE_DIR=/Users/yourusername/anaconda3/include/python3.6m \
    -D PYTHON_DEFAULT_EXECUTABLE=/Users/yourusername/anaconda3/bin/python3 \
    -D PYTHON_PACKAGES_PATH=/Users/yourusername/anaconda3/lib/python3.6/site-packages \
    -D INSTALL_C_EXAMPLES=OFF \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D BUILD_EXAMPLES=ON \
    -D BUILD_opencv_python3=ON \
    -D BUILD_opencv_python2=OFF \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..
$ make -j4
$ make install

À ce stade, l'installation aurait dû se dérouler sans heurts. Cependant, si vous allez au terminal, vous aurez toujours:

$ python
import cv2
ImportError: No module named cv2

Alors maintenant, renommez ce fichier

$ cd ~/opencv/lib/python3.6/site-packages
$ mv cv2.cpython-36m-darwin.so cv2.so

et le copier à cet endroit

$ cp cv2.so /Users/yourusername/anaconda3/lib/python3.6/site-packages

et maintenant ça devrait marcher. 

$ python
import cv2
cv2.__version__
'3.2.0-dev'
6
Sean L

J'ai installé anaconda3 sur Win10, et j'ai eu la même erreur lorsque j'installais opencv3 avec conda: conda install -c menpo opencv3

Cherché un moment, j'ai vu cette question et une autre similaire sur groupes Google ici . D'une manière ou d'une autre, j'ai réussi à installer opencv3 dans un env virtuel python35, qui pourrait également fonctionner sous Mac OS. 

conda create --name python35 python=3.5
activate python35
conda install -c menpo opencv3

Relancez ensuite Anaconda3 Navigator et choisissez l’environnement python35. 

Avoir un test dans Spyder:

import cv2
print(cv2.__version__)
3.1.0
4
Yuk

Mise à jour: Conda a un paquet OpenCV pré-construit pour Python 3.6 maintenant!

La solution directe serait simplement de faire ce qui suit dans l’installation de base

conda install -c menpo opencv3

Auparavant, les paquetages étaient construits jusqu'à Python 3.5, je résolvais donc ce problème avec l'alternative de @ VivekPatani .

Actuellement, le référentiel de conda menpo dispose d'une version pré-construite d'OpenCV pour Python 3.6. Par conséquent, il ne serait pas nécessaire de passer à la version 3.5 ou de créer OpenCV à partir de la source. 

1
Ébe Isaac