ModuleNotFoundError:在 vscode 中没有使用 venv 的名为“请求"的模块 [英] ModuleNotFoundError: No module named 'requests' using venv in vscode
问题描述
我有 1 个文件,直到第 1 行 import requests
,仅此而已,我收到以下 error ModuleNotFoundError: No module named 'requests'
.
I have 1 file, i get as far as line 1 import requests
, nothing more yet and I receive the following error ModuleNotFoundError: No module named 'requests'
.
- 使用 Visual Studio Code,今天安装了独立的 Python x64 3.7.4
- 安装在 VSCODE 中的 Python 扩展
- 在 VSCODE 中创建的 venv 作为 VSCODE 终端内工作区的子文件夹,并在创建时被 VSCODE 识别,我正在 VSCODE 中使用 venv 解释器,如底部栏所示
- 在 VSCODE 内的终端内运行
pip install requests
- 成功完成 - 运行
pip freeze
以确认请求==2.22.0 已注册 - 经过验证的 pylint 已安装在 venv 中
- Using Visual Studio Code, installed today with standalone Python x64 3.7.4
- Python Extension installed in VSCODE
- venv created within VSCODE as a subfolder of workspace withint VSCODE terminal and was recognized by VSCODE when created and I am using venv interpreter in VSCODE as indicated on bottom bar
- ran
pip install requests
within terminal inside VSCODE - completed successfully - ran
pip freeze
to confirm requests==2.22.0 is registered - Verified pylint was installed in venv
我不明白为什么 VSCODE python 解释器无法识别请求已安装
I cannot figure out why VSCODE python interpreter will not recognize that requests is installed
推荐答案
感谢您的回复.几个小时后,我发现了自己的问题.
Thanks for the responses. I found out my own issue after a few hours.
首先,我发现当我在 VSCODE 中运行终端时,它是针对全局解释器运行的.然后我尝试了 ./pip freeze
并且它按预期工作.这告诉我终端连接到错误的解释器.
First off I figured out somewhere that when I was running the terminal in VSCODE it was running against global interpreter. I then tried ./pip freeze
and it worked as expected. This told me that the terminal was connected to the wrong interpreter.
出于某种原因,当我运行"它在终端中执行的文件但它没有激活"venv 时.我已经多次关闭并重新打开 VSCODE,但是出于某种原因,当我关闭终端窗口并使用 CTRL+SHIFT+' 重新打开时,当它尝试使用 PS1 脚本激活我的 venv 时,我收到了有关签名脚本的错误.我在普通 PowerShell 窗口中运行 Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
然后在 VSCODE 中重新打开终端窗口,它成功激活了我的 venv,我知道在终端行的开头看到我的 venv 名称.然后我运行 'pip freeze' 以确认哪些模块安装在 venv 中,然后在正常的 powershell 窗口中再次运行,结果有所不同.
For some reason when I would 'run' the file it was executing in the terminal but it wasn't 'activating' the venv. I've closed and reopened VSCODE many times but for some reason when I closed the terminal window and reopened using CTRL+SHIFT+' and I received an error about signed scripts when it tried to activate my venv using the PS1 script. I ran Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
inside a normal PowerShell window and then reopened the Terminal window in VSCODE and it successfully activated my venv and I know see my venv name at the beginning of the line of the terminal. I then ran 'pip freeze' to confirm which modules installed inside of venv and then ran again in normal powershell window and it was different.
某处有文档说要运行 Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
,我后来发现了它,但如果知道这是一个要求就好了.
There is documentation somewhere that says to run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
which I found later, but it would have been nice to know this was a requirement.
这篇关于ModuleNotFoundError:在 vscode 中没有使用 venv 的名为“请求"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!