macos - 如何克服以下opencv问题安装?

标签 macos python-2.7 python-3.x opencv macos-sierra

您好我正在尝试运行 github 存储库:

https://github.com/oarriaga/face_classification

如下:

MacBook-Pro:~/Downloads/face_classification-master$ pip install -r REQUIREMENTS.txt 
Collecting keras==2.0.3 (from -r REQUIREMENTS.txt (line 1))
  Using cached Keras-2.0.3.tar.gz
Collecting tensorflow==1.1.0 (from -r REQUIREMENTS.txt (line 2))
  Using cached tensorflow-1.1.0-cp27-cp27m-macosx_10_11_x86_64.whl
Collecting pandas==0.19.1 (from -r REQUIREMENTS.txt (line 3))
  Using cached pandas-0.19.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting numpy==1.12.1 (from -r REQUIREMENTS.txt (line 4))
  Using cached numpy-1.12.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting h5py==2.7.0 (from -r REQUIREMENTS.txt (line 5))
  Using cached h5py-2.7.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting statistics (from -r REQUIREMENTS.txt (line 6))
  Using cached statistics-1.0.3.5.tar.gz
Collecting opencv2-python==3.2.0 (from -r REQUIREMENTS.txt (line 9))
  Could not find a version that satisfies the requirement opencv2-python==3.2.0 (from -r REQUIREMENTS.txt (line 9)) (from versions: )
No matching distribution found for opencv2-python==3.2.0 (from -r REQUIREMENTS.txt (line 9))

但是我在使用 opencv 时遇到了错误,然后我尝试了:
MacBook-Pro:~/Downloads/face_classification-master$ pip3 install -r REQUIREMENTS.txt 
Collecting keras==2.0.3 (from -r REQUIREMENTS.txt (line 1))
  Using cached Keras-2.0.3.tar.gz
Requirement already satisfied: tensorflow==1.1.0 in /usr/local/lib/python3.6/site-packages (from -r REQUIREMENTS.txt (line 2))
Collecting pandas==0.19.1 (from -r REQUIREMENTS.txt (line 3))
  Using cached pandas-0.19.1.tar.gz
Collecting numpy==1.12.1 (from -r REQUIREMENTS.txt (line 4))
  Using cached numpy-1.12.1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Requirement already satisfied: h5py==2.7.0 in /usr/local/lib/python3.6/site-packages (from -r REQUIREMENTS.txt (line 5))
Collecting statistics (from -r REQUIREMENTS.txt (line 6))
  Using cached statistics-1.0.3.5.tar.gz
Collecting opencv2-python==3.2.0 (from -r REQUIREMENTS.txt (line 9))
  Could not find a version that satisfies the requirement opencv2-python==3.2.0 (from -r REQUIREMENTS.txt (line 9)) (from versions: )
No matching distribution found for opencv2-python==3.2.0 (from -r REQUIREMENTS.txt (line 9))

我也试过:
MacBook-Pro:~/Downloads/face_classification-master$ brew install opencv3 --with-ffmpeg --with-tbb --with-contrib
==> Installing opencv3 from homebrew/science
==> Installing dependencies for homebrew/science/opencv3: cmake, pkg-config, lame, x264, xvid, ffmpeg, tbb
==> Installing homebrew/science/opencv3 dependency: cmake
==> Downloading https://homebrew.bintray.com/bottles/cmake-3.8.2.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring cmake-3.8.2.sierra.bottle.tar.gz
==> Using the sandbox
==> Caveats
Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/cmake
==> Summary
🍺  /usr/local/Cellar/cmake/3.8.2: 2,208 files, 29.2MB
==> Installing homebrew/science/opencv3 dependency: pkg-config
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.2.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pkg-config-0.29.2.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/pkg-config/0.29.2: 11 files, 627KB
==> Installing homebrew/science/opencv3 dependency: lame
==> Downloading https://homebrew.bintray.com/bottles/lame-3.99.5.sierra.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring lame-3.99.5.sierra.bottle.1.tar.gz
🍺  /usr/local/Cellar/lame/3.99.5: 26 files, 2MB
==> Installing homebrew/science/opencv3 dependency: x264
==> Downloading https://homebrew.bintray.com/bottles/x264-r2748.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring x264-r2748.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/x264/r2748: 11 files, 3.3MB
==> Installing homebrew/science/opencv3 dependency: xvid
==> Downloading https://homebrew.bintray.com/bottles/xvid-1.3.4.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring xvid-1.3.4.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/xvid/1.3.4: 9 files, 1.2MB
==> Installing homebrew/science/opencv3 dependency: ffmpeg
==> Downloading https://homebrew.bintray.com/bottles/ffmpeg-3.3.2.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring ffmpeg-3.3.2.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/ffmpeg/3.3.2: 243 files, 50.7MB
==> Installing homebrew/science/opencv3 dependency: tbb
==> Downloading https://homebrew.bintray.com/bottles/tbb-2017_U7.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring tbb-2017_U7.sierra.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/adolfocamachogonzalez/Library/Python/2.7/lib/python/site-packages
  echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/adolfocamachogonzalez/Library/Python/2.7/lib/python/site-packages/homebrew.pth
==> Summary
🍺  /usr/local/Cellar/tbb/2017_U7: 119 files, 1.9MB
==> Installing homebrew/science/opencv3 --with-contrib --with-tbb --with-ffmpeg
==> Downloading https://github.com/opencv/opencv/archive/3.2.0.tar.gz
==> Downloading from https://codeload.github.com/opencv/opencv/tar.gz/3.2.0
######################################################################## 100.0%
==> Downloading https://github.com/opencv/opencv_contrib/archive/3.2.0.tar.gz
==> Downloading from https://codeload.github.com/opencv/opencv_contrib/tar.gz/3.2.0
######################################################################## 100.0%
==> Downloading https://raw.githubusercontent.com/opencv/opencv_3rdparty/81a676001ca8075ada498
######################################################################## 100.0%
==> cmake .. -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -DCMAKE_INSTA
==> make
==> make install
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because opencv3 and opencv install many of the same files.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/opencv3/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/opencv3/lib
    CPPFLAGS: -I/usr/local/opt/opencv3/include
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/opencv3/lib/pkgconfig


If you need Python to find bindings for this keg-only formula, run:
  echo /usr/local/opt/opencv3/lib/python2.7/site-packages >> /usr/local/lib/python2.7/site-packages/opencv3.pth
  mkdir -p /Users/adolfocamachogonzalez/Library/Python/2.7/lib/python/site-packages
  echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/adolfocamachogonzalez/Library/Python/2.7/lib/python/site-packages/homebrew.pth
==> Summary
🍺  /usr/local/Cellar/opencv3/3.2.0: 498 files, 63.2MB, built in 6 minutes 58 seconds

之后,当我尝试运行代码时出现错误:
MacBook-Pro:~/Downloads/face_classification-master/src$ python video_test.py 
Traceback (most recent call last):
  File "video_test.py", line 1, in <module>
    import cv2
ImportError: No module named cv2

因此,我真的很感谢对此的支持。

最佳答案

如错误消息所述,您缺少 opencv 的 python 绑定(bind)。
使用自制软件安装时,您必须添加 --with-python或/和 --with-python3听从你的命令。

brew install opencv3 --with-ffmpeg --with-tbb --with-contrib --with-python

关于macos - 如何克服以下opencv问题安装?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45067543/

相关文章:

macos - 将本地IP映射到外部/主机IP…IP转发?

java - Mac 上 IntelliJ ide 中出现错误 "class not found"

python-2.7 - Python “expected an indented block”

python - 在 python 3 中使用 cElementTree

swift - 代码在 Xcode 8 中不起作用

ios - 如何使用 Foundation 框架在 Swift 中创建和运行线程?

Python Pandas.Series.asof : Cannot compare type 'Timestamp' with type 'struct_time'

python-2.7 - 在 pymc3 : how? 之外使用 pymc3 可能性/后验

python - (Cython) 在 __pow__ 中使模参数可选

python - 基于多个条件创建 Pandas Dataframe 列