简体   繁体   English

cv2 安装成功后无法导入

[英]cv2 won't import after successfully installing it

I have a single .py file with nothing in it except import cv2 .我有一个.py文件,其中除了import cv2之外什么都没有。 When I run: pip install opencv-python , it tells me that requirements are already satisfied but when I run it, it tells me there is "No module named cv2"当我运行: pip install opencv-python时,它告诉我要求已经满足,但是当我运行它时,它告诉我“没有名为 cv2 的模块”

I'm using VSCode with Python 3.9.1我在 Python 3.9.1 中使用 VSCode

How could I solve this issue??我该如何解决这个问题?

if you are using python 3 you should use如果您使用的是 python 3,您应该使用

pip3 install package <name>

or pip install package as python 2X或 pip 安装包为 python 2X

you can try some different method here : https://java2blog.com/modulenotfounderror-no-module-named-cv2-python/你可以在这里尝试一些不同的方法: https ://java2blog.com/modulenotfounderror-no-module-named-cv2-python/

Your pip command may be connected to the python 3.7 because it works well when you change python interpreter.您的 pip 命令可能连接到 python 3.7,因为它在您更改 python 解释器时运行良好。

  1. Change your python interpreter to you want to use (3.9)将您的 python 解释器更改为您想要使用的 (3.9)
  2. Check the interpreter is set correctly.检查解释器是否设置正确。
python -V
  1. Install OpenCV安装 OpenCV
python -m pip install opencv-python

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM