'VSCode and Venvs: Unable to run pip install
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.
Solution 1:[1]
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).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ulu83 |
