Install Python Library in Visual Studio Code

Posted by John Liu on Thursday, April 25, 2024

In Visual Studio Code Python project, you can create a Python virtual environment for your project. Open Command Palette (Ctrl+Shift+P), search for Pyton: Create Environment command.

This will auto set the workspace environment to the newly created virtual environment. Now in the terminal, run the pip install for the library needed.

pip install <library>

Alternativly, you can run following script to create the virtual environment (named venv or whatelse you prefer):

python -m venv <your project folder>\venv

This will create a venv folder under your project folder. Then run following script to activate your virtual environment:

& <your project folder>\venv\Scripts\Activate.ps1

References:

Python environments in VS Code
How to install Python Libraries in Visual Studio Code