Python virtual environments prevent package conflicts in Python projects. Using pip
inside a virtual environment (or per-user) keeps your system Python stable and makes installs, upgrades, and uninstalls straightforward, as documented in the Python Packaging User Guide at packaging.python.org and the official docs at docs.python.org.
Method 1 — Use pip inside a virtual environment (recommended)
Step 1: Check that Python is available.
python --version
Step 2: Check that pip is available.
python -m pip --version
Step 3: Create a virtual environment.
python -m venv .venv
Step 4: Activate the virtual environment.
# Unix/macOS
source .venv/bin/activate
# Windows
.\.venv\Scripts\activate
Step 5: Upgrade pip, setuptools, and wheel inside the venv.
python -m pip install --upgrade pip setuptools wheel
Step 6: Install a package from PyPI.
python -m pip install "SomeProject"
Step 7: Pin specific versions using standard specifiers (PEP 440).
# exact version
python -m pip install "SomeProject==1.4"
# version range
python -m pip install "SomeProject>=1,<2"
# compatible release (e.g., 1.4.* and >=1.4.2)
python -m pip install "SomeProject~=1.4.2"
Step 8: Record your environment to a requirements file.
python -m pip freeze > requirements.txt
pip prefers prebuilt wheels for faster, more reliable installs and will build a wheel locally if only a source archive is available. You can override binary usage with --no-binary
when needed.
Method 2 — Install to the user site (no admin rights required)
Step 1: Install a package just for your user account.
python -m pip install --user SomeProject
Step 2: Add the user scripts directory to your PATH
if command-line scripts are not found.
# Linux/macOS: get base dir, then add "bin" to PATH
python -m site --user-base
# Windows: get user site path, then replace "site-packages" with "Scripts"
py -m site --user-site
Note that --user
has no effect inside a virtual environment—everything installs into that venv.
Method 3 — Install from a requirements file
Step 1: Place a requirements.txt
file in your project with one requirement per line.
Step 2: Install all pinned dependencies in one command.
python -m pip install -r requirements.txt
Method 4 — Advanced pip options
Step 1: Install an editable project from a VCS URL.
python -m pip install -e SomeProject @ git+https://github.com/org/repo.git
Step 2: Install a pre-release or development build.
python -m pip install --pre SomeProject
Step 3: Install package “extras” (optional features).
python -m pip install "SomePackage[PDF]"
Step 4: Install from a local archive or directory.
# from a local file
python -m pip install ./downloads/SomeProject-1.0.4.tar.gz
# from a local directory (editable)
python -m pip install -e .
Step 5: Use a private or alternate package index when required.
# replace URL with your repository
python -m pip install --index-url https://my.repo/simple SomeProject
See pip’s reference for VCS support and other options in the official docs at pip.pypa.io.
Method 5 — Fix common install issues
Step 1: Use module-invocation to avoid PATH issues.
python -m pip --version
Step 2: Bootstrap pip if it is missing.
python -m ensurepip --default-pip
Step 3: If needed, install via get-pip.py
with caution on OS-managed Python.
# securely download get-pip.py using a browser or TLS-verifying tool
# then run:
python get-pip.py
# to avoid interfering with system-managed Python on Unix-like OSes:
python get-pip.py --prefix=/usr/local/
Step 4: Prefer python3
on Linux distributions and avoid sudo
for pip commands.
# Linux example: per-user install without sudo
python3 -m pip install --user SomeProject
Step 5: Run shell commands from Jupyter by prefixing with !
and use the current kernel’s Python.
import sys
!{sys.executable} --version
!{sys.executable} -m pip install "SomeProject"
The official guidance above (including avoiding sudo
, using virtual environments, and managing PATH for user installs) is covered in the Python Packaging User Guide at packaging.python.org and Python’s “Installing Python Modules” at docs.python.org. Version specifiers follow PEP 440 at peps.python.org, and virtual environment details are in the venv documentation.
With pip plus venv or per-user installs, you keep your system Python intact, eliminate permission headaches, and make dependency management reproducible. Save your requirements and you can recreate environments quickly on any machine.
Member discussion