[英]how to clear unresolved import 'cv2' error?
I have installed Python 3.9 on my ubuntu 18.04 desktop, i have already installed two libraries using pip3 install 1)opencv-contrib-python 2)opencv-python我已经在我的 ubuntu 18.04 桌面上安装了 Python 3.9,我已经使用pip3 install安装了两个库 1)opencv-contrib-python 2)opencv-python
Currently i am writing a program in VSCode for which i am importing cv2目前我正在VSCode中编写一个程序,我正在为其导入 cv2
I have already default version of python 3.6.9 in my computer.我的电脑中已经有python 3.6.9的默认版本。 When i use default version as interpreter, program seems to be working fine .But if i switch the interpreter to newly installed python 3.9 , i get an error ModuleNotFoundError: No module named 'cv2'
当我使用默认版本作为解释器时,程序似乎工作正常。但是如果我将解释器切换到新安装的python 3.9 ,我会收到错误ModuleNotFoundError: No module named 'cv2'
please someone who has faced such problem and know how to resolve it help me......请遇到过此类问题并知道如何解决的人帮助我......
The reason is as you described: it is due to the use of the Python environment.原因如您所述:是由于使用了Python环境所致。
The module " cv2
" is installed in " lib\site-packages\
" in python3.6.9, but when we use "python3.9" without the module " cv2
" installed, VS Code is in "python3.9" The module could not be found in " lib\site-packages\
".模块“
cv2
”安装在python3.6.9的“ lib\site-packages\
”中,但是当我们在没有安装模块“ cv2
”的情况下使用“python3.9”时,VS Code在“python3.9”中的模块可以在“ lib\site-packages\
”中找不到。
You could use the command " pip3 --version
" to check the source of the module installation tool, the module is installed in " lib\site-packages\
" here:您可以使用命令“
pip3 --version
”来检查模块安装工具的来源,模块安装在“ lib\site-packages\
”这里:
When using the command " pip3 show opencv-python
" to check its installation location: (...\python\python38\lib\site-packages)使用命令“
pip3 show opencv-python
”检查其安装位置时:(...\python\python38\lib\site-packages)
Therefore, if you want to use the module "cv2" in "python3.9", please install it in this environment.因此,如果要在“python3.9”中使用模块“cv2”,请在此环境下安装。 In addition, it is recommended that you use a virtual environment , it will be stored in "lib\site-packages" in the folder of the project so that you could check it more intuitively.
另外,建议您使用虚拟环境,它将存放在项目文件夹的“lib\site-packages”中,以便您更直观地查看。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.