To install a Python library in Visual Studio Code, first select (or create) the project’s Python environment, then install the package into that environment. Install three separate components—VS Code, a Python interpreter, and Microsoft’s Python extension—open your project folder, create or select a virtual environment, and use either Manage Packages or the integrated terminal.
What you need before installing a library
- Visual Studio Code: the editor and workspace.
- A Python interpreter: the program that runs Python. It is installed separately from VS Code and its extension. See Microsoft’s Python in Visual Studio Code overview.
- The Microsoft Python extension: adds interpreter selection, IntelliSense, running, debugging, and environment management. Install it from the Extensions view.
Python packages and Python libraries usually mean the same thing in this context. Package-installation commands use the term package.
Create or select the project environment first
Installing into the environment selected by VS Code prevents the common situation where a package is installed successfully but cannot be imported by your project. Microsoft describes a project-specific virtual environment as a best practice because it keeps dependencies isolated from other projects.
- Open your project folder in VS Code.
- Open the Command Palette with Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on macOS.
- Run Python: Create Environment.
- Choose Venv, then select the installed Python interpreter.
- Run Python: Select Interpreter and confirm that the new environment is selected.
The current Python environments in VS Code guide also documents Quick Create and Custom Create. VS Code can create venv and Conda environments; environments managed by tools such as Poetry or Pipenv are created through those tools’ own command-line workflows.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
Install a package with the VS Code interface
- Open the Python sidebar.
- Expand Environment Managers.
- Right-click the environment you selected for the project and choose Manage Packages.
- Search for the package name, select the result, and choose Install.
This route is useful when you want to choose a package from VS Code rather than type a command. Confirm the environment name before installing; the package must be added to the environment your project uses. The Environments guide also describes installing dependencies declared in supported files such as requirements.txt and pyproject.toml.
Install a package from the integrated terminal
Open Terminal > New Terminal after selecting the interpreter, then run the command that matches your operating system and interpreter command:
Rank #2
| System or setup | Command |
|---|---|
| Windows | python -m pip install package_name |
macOS or Linux, when the interpreter command is python3 |
python3 -m pip install package_name |
Replace package_name with the package’s published name. For example, the official tutorial uses python3 -m pip install numpy on macOS/Linux and python -m pip install numpy on Windows. Using python -m pip (or python3 -m pip) runs pip through that interpreter, reducing the chance of installing into a different Python installation. See Getting Started with Python in VS Code for the documented workflow.
Install all dependencies declared by a project
requirements.txt
If the project includes a requirements.txt file, select the project environment and use VS Code’s environment creation or dependency-install flow to install the listed packages. After activating an environment, you can record its installed dependencies with:
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →pip freeze > requirements.txt
pyproject.toml
Projects may declare dependencies in pyproject.toml. Use the package manager and installation procedure required by that project, while keeping the project environment selected in VS Code. The Environments documentation covers dependency installation from supported project files.
Choose the package manager that matches the environment
| Installation route | Best suited to | Important check |
|---|---|---|
| Manage Packages | Installing from VS Code’s environment interface | Verify that the right environment is selected before searching and installing. |
python -m pip install … |
venv environments and projects that specify pip commands | Use the terminal associated with the selected interpreter; use python3 where that is the interpreter command. |
requirements.txt or pyproject.toml |
Projects with a declared dependency set | Install into the project environment and follow the project’s stated package-manager workflow. |
| Conda | Projects using a Conda environment | Use Conda’s package-management commands rather than treating the environment as a generic venv. |
VS Code’s environment guide documents pip for venv and conda for Conda environments, with optional uv support for venv workflows. It describes uv as significantly faster for large dependency trees but does not provide a benchmark figure. See Python environments in VS Code.
Verify that VS Code can use the installed package
- Look at the Python environment indicator in the VS Code Status Bar.
- Run Python: Select Interpreter and confirm the intended environment.
- Open a new integrated terminal after selecting it, then install the package there if necessary.
- Run or debug the project and check the import again.
VS Code uses the selected environment for language features and activates it when running or debugging Python and when creating a new terminal. The Python settings reference explains interpreter-related settings.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Fix an “import could not be resolved” or missing-package error
The package was installed into another interpreter
This is the most common cause. Select the interpreter where the package is installed, or install the package again from a terminal associated with the interpreter currently selected by VS Code. Installing into one Python installation does not make the package available to every other environment.
Best Value
The wrong environment is selected
Use Python: Select Interpreter, choose the project’s venv or Conda environment, and open a new terminal. Then rerun the installation command with that environment’s python or python3 executable.
The environment was created without the project dependencies
Recreate or update the environment using the project’s requirements.txt or pyproject.toml, following the project’s documented package manager. VS Code’s environment workflow can detect dependency files during creation and installation.
For additional interpreter and import guidance, see Microsoft’s Editing Python in Visual Studio Code and Quick Start Guide for Python in VS Code.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →

