Install Python packages from a terminal with python -m pip (or the platform-specific Python launcher), preferably inside a project virtual environment. If an install fails, first check which Python interpreter and environment your command is using; the right fix depends on the error, operating system, and package.
Install a package in a project virtual environment
A virtual environment keeps a project’s third-party packages separate from other projects and from Python managed by your operating system. The Python Packaging User Guide recommends this approach for project work. Open a terminal in your project directory, then create and activate an environment.
Unix and macOS
python3 --versionchecks that Python is available.python3 -m venv .venvcreates an environment in the project’s.venvdirectory.source .venv/bin/activateactivates it in the current shell.python -m pip install requestsinstalls the example package into the active environment.
Windows
py --versionchecks that the Python launcher can find Python.py -m venv .venvcreates the environment..venvScriptsactivateactivates it in Command Prompt.python -m pip install requestsinstalls the example package into the active environment.
Activation puts the environment’s Python and pip on the shell’s PATH, so python -m pip targets that environment. Add .venv to your version-control ignore rules rather than committing the environment. When you return to the project in a new terminal, activate the existing environment again; you do not need to recreate it. Run deactivate when you are finished in that shell.
Install or update packages from the terminal
Run pip commands in a terminal or shell, not at Python’s >>> prompt. Use the Python module form of pip to make clear which interpreter is running it; a bare pip may refer to a different Python installation.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
- Unix/macOS, outside a virtual environment:
python3 -m pip install SomePackage. - Windows, outside a virtual environment:
py -m pip install SomePackage. - Upgrade a named package: add
--upgrade, for examplepython -m pip install --upgrade requests. - Install the dependencies listed in a requirements file:
python -m pip install -r requirements.txt.
Replace SomePackage with the package’s distribution name. Its name for installation is not always the same as the name used in an import statement; check that package’s documentation for the import name. If you specify version constraints, quote them when required by your shell.
Check Python and pip before troubleshooting
These checks show whether the selected interpreter exists and whether pip is available for it:
Rank #2
- Unix/macOS:
python3 --version, thenpython3 -m pip --version. - Windows:
py --version, thenpy -m pip --version.
Inside an activated virtual environment, use python -m pip --version. The reported location helps confirm that pip belongs to the interpreter you intend to use.
Fix common pip errors
No module named pip or pip is unavailable
First run the pip version check with the interpreter you intend to use. If pip is missing, try Python’s standard-library bootstrapper: python3 -m ensurepip --default-pip on Unix/macOS or py -m ensurepip --default-pip on Windows. On Linux, Python installed through the operating system’s package manager may require that distribution’s pip package. The Packaging User Guide describes get-pip.py as a further fallback, but warns it can leave operating-system- or package-manager-managed Python installations inconsistent; do not treat it as the routine first fix.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Permission denied or an externally managed environment
Do not reflexively add sudo to a pip command. The Python Packaging User Guide’s Linux/system-Python note says: “Do not run any of the commands in this tutorial with sudo: if you get a permissions error, come back to the section on creating virtual environments, set one up, and then continue with the tutorial as written.” For a project, create a virtual environment and install into it. If the operating system manages the Python installation, use its supported packages or a virtual environment instead of overwriting files it controls.
An externally managed environment message reflects policy around a Python installation managed outside pip. The precise message and appropriate option can vary by distribution and installation; the Python Packaging Authority’s specification explains that boundary. A user-site install is another pip option in some situations, but it is not a universal workaround: --user has no effect inside a standard isolated virtual environment, and installed scripts may be outside your PATH.
The install succeeds, but importing the package fails
Check for an interpreter mismatch before reinstalling. In Unix/macOS, which python shows the selected executable; on Windows, use where python. When working in a virtual environment, the selected path should point inside .venv. Also confirm the package’s documented import name, which may differ from its pip distribution name.
In a Jupyter or IPython notebook, an install command can target a different Python than the notebook kernel. Use the running kernel’s executable so pip installs into that interpreter:
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 →Best Value
import sys
!{sys.executable} -m pip install requests
A dependency conflict or resolver error
A resolver error usually means the requested versions cannot all satisfy the packages’ declared requirements. Review version pins and the requirements of the packages involved, then test a compatible set together in a clean project environment. Installing packages in separate pip commands can lead to a different result from asking pip to resolve the intended set at once. python -m pip check reports inconsistencies among packages already installed in the current environment; it does not decide which versions your project should use.
A network, proxy, certificate, or download error
pip must reach a package index to download packages. On a managed network, check whether your organization requires an outbound HTTP proxy. pip supports a --proxy option, configuration-file settings, and the http_proxy or https_proxy environment variables. Diagnose the exact error for proxy configuration, certificate trust, DNS, or network policy. Disabling TLS verification is not a safe general-purpose fix.
Failed building wheel or another source-build error
pip prefers a compatible wheel archive when one is available; if it cannot find a satisfactory wheel, it may use a source archive and attempt a build. That build can require package-specific compilers or libraries, or the package may not support your Python version or platform. Check the package’s supported Python and platform combinations and whether a compatible wheel is available. The package name, operating system, Python version, and full error log are needed to narrow down a specific build failure.
Choose an installation approach that fits the job
| Approach | Isolation | Who manages Python? | Best fit |
|---|---|---|---|
Project venv |
Project dependencies are isolated from other environments. | You manage the project environment; the base Python may be managed by the OS or another installer. | Libraries and tools needed by a particular project. |
| Operating-system packages | Managed according to the distribution’s package model. | The operating system’s package manager. | Packages the distribution supports for its Python installation. |
| User-site pip install | Separate from system-wide package files, but not equivalent to a project-specific environment. | pip installs for the current user; script locations may need PATH configuration. | Cases where a user-level install is suitable and supported. |
| pipx | Isolates standalone Python command-line applications. | pipx manages the application’s environment. | Installing a command-line application for use outside one project, rather than a library dependency. |
Choose package sources deliberately
pip can install from package indexes, version-control repositories, local projects, and distribution files. These sources are not interchangeable convenience options: consider who controls the source, whether the version is reproducible, and whether it supports your Python and platform. For ordinary project work, prefer the project’s trusted package index and declared requirements. Treat an arbitrary index URL or source repository as a trust decision.
Quick Recap
Official references
- Python Packaging User Guide: Installing Packages
- Python Packaging User Guide: Installing Packages Using pip and Virtual Environments
- pip User Guide
- Externally Managed Environments specification
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.

