ModuleNotFoundError: No module named 'cv2'

半世苍凉 提交于 2019-12-19 07:22:35

问题


I have been working on this error for a long time now. I have Python 3.6 and Python 2.7. I have tried to install opencv 2 and 3 in Python 2.7 and Python 3.6 respectively. I know the python interpreter I am using and I can interchange between them when I want.

When I run Python interpreter and write import cv2 it does import it. When I run the code from command prompt it says ModuleNotFoundError: No module named 'cv2'. The module is installed. The cv2.pyd file is in C:\Python27\Lib\site-packages I have attached a screen shot which shows the modules in Python27

I have used pip install opencv-python. I have downloaded the module from different sites and manually copy pasted it in the correct folder. Nothing works and I am seriously short of ideas now.

EDIT: I am on windows 10 with python 3.6 installed through anaconda and python 2.7 installed directly. Both have their variables set in the path


回答1:


Faced with the same issue on Windows 10 I downloaded the open cv binary from the Unofficial Windows Binaries for Python Extension Packages.

Search the page for opencv and for and download the correct .whl for your system. Then pip install it. By example, on my system, after opening a cmd window I typed the following.

pip install opencv_python-3.4.1-cp36-cp36m-win_amd64.whl

I then opened python and the following worked

import cv2
print(cv2.__version__)

More info is available in this Mark Jay video.

:D




回答2:


In Windows 10 you can install it as

pip install opencv-python

this will allow you to import cv2 module



来源:https://stackoverflow.com/questions/46854330/modulenotfounderror-no-module-named-cv2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!