VSCODE和VENVS:无法运行PIP安装

发布于 2025-01-25 22:15:44 字数 355 浏览 1 评论 0原文

我正在Win10上的Visual Studio代码中运行Python 3.9。我试图将Beautifulsoup(BS4)导入VENV,但没有运气。我会遇到以下错误:

  • 无法从源幽门中解析
  • 在编辑期间,Pylance说:从vScode“ play”按钮运行Python时,

,我得到了一个ModulenotFoundError:没有名为'bs4'的模块,但我以前已经安装了BS4使用终端!当我输入时

python3 -m pip install bs4

,我会得到“需求已经满足”。有什么问题?我正在使用VSCODE中的VENV,并在终端中被激活并被选为解释器。

I am running Python 3.9 in Visual Studio Code on Win10. I am trying to import BeautifulSoup (bs4) into a venv, but no luck. I get the following errors:

  • During editing, Pylance says: Import "bs4" could not be resolved from source Pylance
  • When running Python from VSCode "Play" button, I get a ModuleNotFoundError: No module named 'bs4'

But I have previously installed bs4 using the terminal! When I enter

python3 -m pip install bs4

, I get "requirement already satisfied". What can be the problem? I am using a VENV in VSCode, and it is activated in the terminal and selected as the interpreter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泼猴你往哪里跑 2025-02-01 22:15:45

解决我问题的解决方案是在全球范围内安装BS4,而是在VENV上安装本地。而不是仅

python3 -m pip install bs4

运行

pip install bs4

在激活VENV的终端中 。如果未激活VENV,我可以将CD降为.venv/脚本并运行

.\activate.ps1 

(对于Windows PowerShell)。

The resolution to my problem was to install bs4 not globally, but locally in the venv. Instead of running

python3 -m pip install bs4

simply run

pip install bs4

in a terminal that has the VENV activated. If the VENV is not activated, I can CD into .venv/Scripts and run

.\activate.ps1 

(for windows PowerShell).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文