【发布时间】:2018-03-14 03:26:27
【问题描述】:
如何在 OS X 中为 Anaconda Python 安装 OpenCV?我在 Windows 7 Enterprise 中使用了相同的命令,它工作了
Monas-MacBook-Pro:machine_learning mona$ conda install --channel https://conda.anaconda.org/menpo opencv3
Fetching package metadata .............
Solving package specifications: .
UnsatisfiableError: The following specifications were found to be in conflict:
- opencv3 -> python 2.7*
- python 3.6*
Use "conda info <package>" to see the dependencies for each package.
Monas-MacBook-Pro:machine_learning mona$ conda install opencv3
Fetching package metadata ...........
PackageNotFoundError: Packages missing in current channels:
- opencv3
We have searched for the packages in the following channels:
- https://repo.continuum.io/pkgs/main/osx-64
- https://repo.continuum.io/pkgs/main/noarch
- 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
Monas-MacBook-Pro:machine_learning mona$ 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*
- python 3.6*
Use "conda info <package>" to see the dependencies for each package.
更新:我什至尝试使用 conda forge 安装它,但出现此错误
Monas-MacBook-Pro:machine_learning mona$ conda install -c conda-forge opencv
Fetching package metadata .............
Solving package specifications: ^[[A^[[B.
Package plan for installation in environment /Users/mona/anaconda:
The following NEW packages will be INSTALLED:
blas: 1.1-openblas conda-forge
bzip2: 1.0.6-1 conda-forge
ffmpeg: 3.2.4-1 conda-forge
x264: 20131217-3 conda-forge
The following packages will be UPDATED:
h5py: 2.7.0-np112py36_0 --> 2.7.1-py36_1 conda-forge
hdf5: 1.8.17-1 --> 1.8.18-1 conda-forge
numpy: 1.12.1-py36_0 --> 1.12.1-py36_blas_openblas_200 conda-forge [blas_openblas]
opencv: 3.2.0-np112py36_0 conda-forge --> 3.3.0-py36_blas_openblas_200 conda-forge [blas_openblas]
pytables: 3.3.0-np112py36_0 --> 3.4.2-np112py36_1 conda-forge
scikit-learn: 0.19.0-np112py36_0 --> 0.19.0-py36_blas_openblas_201 conda-forge [blas_openblas]
scipy: 0.19.1-np112py36_0 --> 0.19.1-py36_blas_openblas_202 conda-forge [blas_openblas]
The following packages will be SUPERSEDED by a higher-priority channel:
conda: 4.3.27-py36hb556a21_0 --> 4.3.24-py36_0 conda-forge
conda-env: 2.6.0-0 --> 2.6.0-0 conda-forge
Proceed ([y]/n)? y
Invalid choice: y
Proceed ([y]/n)? y
bzip2-1.0.6-1. 100% |#####################################################| Time: 0:00:00 395.79 kB/s
conda-env-2.6. 100% |#####################################################| Time: 0:00:00 993.59 kB/s
x264-20131217- 100% |#####################################################| Time: 0:00:02 1.19 MB/s
ffmpeg-3.2.4-1 100% |#####################################################| Time: 0:00:25 1.60 MB/s
hdf5-1.8.18-1. 100% |#####################################################| Time: 0:00:03 1.31 MB/s
blas-1.1-openb 100% |#####################################################| Time: 0:00:00 816.40 kB/s
numpy-1.12.1-p 100% |#####################################################| Time: 0:00:02 1.52 MB/s
h5py-2.7.1-py3 100% |#####################################################| Time: 0:00:00 1.78 MB/s
scipy-0.19.1-p 100% |#####################################################| Time: 0:00:10 1.55 MB/s
pytables-3.4.2 100% |#####################################################| Time: 0:00:02 1.19 MB/s
scikit-learn-0 100% |#####################################################| Time: 0:00:04 1.32 MB/s
conda-4.3.24-p 100% |#####################################################| Time: 0:00:00 1.59 MB/s
opencv-3.3.0-p 100% |#####################################################| Time: 0:00:22 1.64 MB/s
Monas-MacBook-Pro:machine_learning mona$ python
Python 3.6.2 |Anaconda custom (x86_64)| (default, Jul 20 2017, 13:14:59)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/mona/anaconda/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libopenblasp-r0.2.19.dylib
Referenced from: /Users/mona/anaconda/lib/libopencv_core.3.3.dylib
Reason: image not found
>>>
【问题讨论】:
-
(1)第一个错误与anaconda的性质有关。有一些预打包的二进制文件,但不适用于所有类型的版本。在您的情况下,python 3.6 似乎没有 opencv3-build(但对于 python 2.7)。切换到 2.7 应该可以。或者使用较旧的 opencv2 可能 (2) 我不知道第二个错误,但我会在干净的环境中再试一次。 (3) 这里不是 OSX 用户,但我认为从源代码安装 opencv 并不难(与 windows 相比)。
-
@sascha 是对的,但您不需要切换回 2.7 --- 最新的 menpo 安装程序适用于 Python 3.5;您可以使用
python=3.5标志安装。 -
这是Trouble installing opencv3 with anaconda python 3.6 (on mac) 的副本。前一周我回答了。骗子在这里几乎不会被关闭,所以我也会发布一个答案。