簡體   English   中英

無法在Python 2.7中導入opencv:ImportError:盡管已安裝opencv 3.2.0,也沒有名為cv2的模塊

[英]Can't import opencv in Python 2.7: ImportError: No module named cv2 despite installed opencv 3.2.0

我用brew安裝了opencv 3.2.0,對我來說似乎很成功。 但是,當我嘗試運行此模塊cv2仍然找不到模塊cv2

FF-MBP:read_video_frames ff$ python v2f.py 
Traceback (most recent call last):
  File "v2f.py", line 4, in <module>
    import cv2
ImportError: No module named cv2

brew安裝如下所示:

FF-MBP:read_video_frames ff$ brew install opencv3
==> Installing opencv3 from homebrew/science
==> Installing dependencies for homebrew/science/opencv3: eigen, jpeg, libpng, libtiff, ilmbase, openexr
==> Installing homebrew/science/opencv3 dependency: eigen
==> Downloading https://homebrew.bintray.com/bottles/eigen-3.3.4.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring eigen-3.3.4.sierra.bottle.tar.gz
==> Using the sandbox
🍺  /usr/local/Cellar/eigen/3.3.4: 486 files, 6.5MB
==> Installing homebrew/science/opencv3 dependency: jpeg
==> Downloading https://homebrew.bintray.com/bottles/jpeg-8d.sierra.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring jpeg-8d.sierra.bottle.2.tar.gz
🍺  /usr/local/Cellar/jpeg/8d: 19 files, 708.3KB
==> Installing homebrew/science/opencv3 dependency: libpng
==> Downloading https://homebrew.bintray.com/bottles/libpng-1.6.29.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libpng-1.6.29.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/libpng/1.6.29: 26 files, 1.2MB
==> Installing homebrew/science/opencv3 dependency: libtiff
==> Downloading https://homebrew.bintray.com/bottles/libtiff-4.0.8.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libtiff-4.0.8.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/libtiff/4.0.8: 245 files, 3.4MB
==> Installing homebrew/science/opencv3 dependency: ilmbase
==> Downloading https://homebrew.bintray.com/bottles/ilmbase-2.2.0.sierra.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring ilmbase-2.2.0.sierra.bottle.2.tar.gz
🍺  /usr/local/Cellar/ilmbase/2.2.0: 362 files, 5.6MB
==> Installing homebrew/science/opencv3 dependency: openexr
==> Downloading https://homebrew.bintray.com/bottles/openexr-2.2.0.sierra.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring openexr-2.2.0.sierra.bottle.1.tar.gz
🍺  /usr/local/Cellar/openexr/2.2.0: 131 files, 11.2MB
==> Installing homebrew/science/opencv3
==> Downloading https://homebrew.bintray.com/bottles-science/opencv3-3.2.0.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring opencv3-3.2.0.sierra.bottle.tar.gz
==> 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


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
==> Summary
🍺  /usr/local/Cellar/opencv3/3.2.0: 286 files, 47.4MB

是否因為opencv 3.0+僅使用Python3.x編譯? 我嘗試import cv3不起作用。 感謝任何輸入。 謝謝!

Mac OS X:Sierra 10.12.5

的Python:2.7

OpenCV:3.2.0

使用pip install在Windows中安裝opencv。 要首先安裝,請轉到cmd。 瀏覽到cmd中的opencv。 pip install opencv進行安裝。

其實這解決了! 我設法將其正確安裝在PyCharm上。 教程: https//www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html#d64763e97

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM