[英]Can't import opencv in Python 2.7: ImportError: No module named cv2 despite installed opencv 3.2.0
I used brew
to install opencv 3.2.0 and it seems successful to me. 我用brew
安装了opencv 3.2.0,对我来说似乎很成功。 Yet module cv2
still cannot be found when I tried to run this: 但是,当我尝试运行此模块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
The brew
installation looks like this: 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
Is it because opencv 3.0+
only compiles with Python3.x
? 是否因为opencv 3.0+
仅使用Python3.x
编译? I tried import cv3
- doesn't work. 我尝试import cv3
不起作用。 Appreciate any inputs. 感谢任何输入。 Thank you! 谢谢!
Mac OS X: Sierra 10.12.5 Mac OS X:Sierra 10.12.5
Python: 2.7 的Python:2.7
OpenCV: 3.2.0 OpenCV:3.2.0
Use pip install
to install opencv in windows. 使用pip install
在Windows中安装opencv。 To install first go to cmd. 要首先安装,请转到cmd。 Browse to opencv in cmd. 浏览到cmd中的opencv。 pip install opencv
to install it. pip install opencv
进行安装。
Actually this is solved! 其实这解决了! I managed to get it correctly installed on PyCharm. 我设法将其正确安装在PyCharm上。 Tutorial: https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html#d64763e97 教程: https : //www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html#d64763e97
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.