简体   繁体   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

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.

相关问题 OpenCV 安装成功但导入错误:没有名为“cv2”的模块 - OpenCV installed successfully BUT ImportError: No module named 'cv2' 尽管安装了 opencv,但导入 Cv2 不起作用 - Import Cv2 not working despite opencv installed ImportError:没有使用Python 2.7命名为cv2的模块 - ImportError: No module named cv2 with Python 2.7 已安装 opencv-python 但无法导入(ModuleNotFoundError: No module named &#39;cv2&#39;) - Installed opencv-python but cannot import (ModuleNotFoundError: No module named 'cv2') OpenCV Python - 没有名为 cv2 的模块(再次) - OpenCV Python - No module named cv2 (again) Python / OS X:从源代码安装了OpenCV,但是导入cv2导致ImportError - Python/OS X: Installed OpenCV from source, but import cv2 results in ImportError 导入cv2失败-为Windows安装适用于Python 2.7的OpenCV - import cv2 failed - installing OpenCV for Python 2.7 for Windows Windows:OpenCV 已安装,但在 Python 中出现“无法导入 cv2”错误 - Windows: OpenCV is installed but getting “Unable to import cv2” error in Python 如何在 VsCode 上的 Python 3.7 和 OpenCV 4.1.1 中解决“导入 cv2,导入错误:DLL 加载失败”? - How can I solve "import cv2, ImportError: DLL load failed " in Python 3.7 and OpenCV 4.1.1 on VsCode? 适用于python的OpenCV。 错误:没有名为cv2的模块 - OpenCV for python. Error: no module named cv2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM