How to Use pip install: A Practical Beginner's Guide

Learn to use pip install to add Python packages, manage versions, and install from requirements.txt while keeping dependencies isolated with virtual environments. A clear, step-by-step guide for beginners.

Install Manual
Install Manual Team
·5 min read
Pip Install Guide - Install Manual
Photo by AlfredMullervia Pixabay
Quick AnswerSteps

You will learn how to use pip install to add Python packages, manage versions, and solve common issues. This guide covers basic installs, upgrades, installing from requirements.txt, and using virtual environments. According to Install Manual, Python 3.6+ is recommended and pip should be on PATH for seamless installs in most setups, in most setups.

What pip install does and where it looks for packages

Pip is the Python package installer. By default it searches the Python Package Index (PyPI) to find and download packages. It can also install from other sources like local wheels, a Git repository, or a URL. The command pip install package tells your Python environment to fetch and install the package and any of its dependencies. According to Install Manual, pip uses a simple, deterministic resolver to satisfy dependencies and can use constraints when needed to avoid conflicts. In practice, you’ll often see commands specifying a version like package==1.2.3 or a range like package>=1.0,<2.0. This control helps ensure stability across environments. For most users, sticking to PyPI, virtual environments, and clear version pins is the path to predictable installs.

Setting up Python, pip, and virtual environments

Before you install packages, you need a working Python and pip setup. Install Manual recommends Python 3.6 or newer and ensures pip is available on PATH. Create a clean project environment using a virtual environment to isolate dependencies from system-wide installations. On Windows, you’ll activate via env\Scripts\activate; on macOS/Linux, source env/bin/activate. If you don’t want to enable a full virtual environment, you can use the --user flag for user-level installs, but this is less portable across machines.

Basic usage: installing a package

To install a package, run:

pip install requests

This fetches the latest compatible version from PyPI and installs it with its dependencies. You can specify a version with:

pip install numpy==1.26.0

You can upgrade pip itself to the newest release:

pip install --upgrade pip

For project-specific dependencies, put packages in a requirements.txt file and install with:

pip install -r requirements.txt

For local development, you may install editable packages with the -e flag, or install from a VCS URL. Always confirm compatibility with your Python version.

Upgrading and listing installed packages

To upgrade a package to its latest compatible version, use:

pip install --upgrade <package-name>

To see what you have installed and their versions, run:

pip list

For more details about a package, use:

pip show <package-name>

Regularly reviewing installed dependencies helps you manage security and compatibility across projects.

Using requirements.txt for reproducible installs

Requirements files lock down the exact versions used in a project. Create a file named requirements.txt with lines like:

flask==2.3.2 requests>=2.26.0,<3.0.0

Install all dependencies with:

pip install -r requirements.txt

To generate a current snapshot, you can run:

pip freeze > requirements.txt

Using requirements.txt ensures that teammates and deployment environments use the same package versions.

Working with virtual environments to isolate projects

Virtual environments create separate Python environments with their own site-packages directory, preventing conflicts between projects. Create one with:

python -m venv env

Activate it (Windows):

env\\Scripts\\activate

Activate it (macOS/Linux):

source env/bin/activate

Then install packages inside the activated environment. Deactivate when finished with:

deactivate

This isolation is essential for reliable reproducible installs, especially when juggling multiple projects.

Troubleshooting common issues

If pip isn’t found, ensure Python is installed and that the Scripts/ directory is on PATH. If you encounter SSL or certificate errors, update ca-certificates or disable SSL verification only as a last resort. Network proxies can block access to PyPI; configure pip to use a proxy via --proxy or a pip.ini/pip.conf file. If a package fails to install due to binary wheels, try installing a compiled version or a compatible wheel, or adjust your Python version for compatibility.

Best practices for reliable installs

Pin versions in requirements to ensure reproducibility. Prefer a virtual environment per project and use a dedicated requirements.txt for dependencies. Keep pip itself up to date with --upgrade. Prefer wheel distributions for faster installs, and consider using a private index or a trusted mirror in enterprise environments. Always review change logs before upgrading critical packages.

Real-world workflow: 15-minute setup

  1. Install Python and verify pip is accessible. 2) Create and activate a new virtual environment. 3) Install core dependencies from a requirements.txt. 4) Test the environment with a minimal script or import. 5) Document exact package versions for teammates. This pragmatic workflow minimizes surprises and improves reliability across development, testing, and production environments.

Authority Sources

For official guidance, consult: https://packaging.python.org/guides/installing-using-pip/ and https://docs.python.org/3/installing/. Additional details are available at https://docs.python.org/3/library/venv.html

Tools & Materials

  • Python 3.6+ interpreter(Ensure it's installed and added to PATH)
  • pip (comes with Python ≥3.4)(If missing, run python -m ensurepip)
  • Command-line terminal(PowerShell/CMD on Windows; Terminal on macOS/Linux)
  • Virtual environment tool (venv)(Create isolated environments with python -m venv env)
  • Internet connection(Needed to fetch packages from PyPI)
  • Text editor (optional)(For editing requirements.txt or docs)

Steps

Estimated time: 15-25 minutes

  1. 1

    Verify prerequisites

    Open a terminal and run python --version and pip --version to confirm installation. If either is missing, install Python 3.6+ and ensure pip is included.

    Tip: Knowing exact versions helps diagnose compatibility issues later.
  2. 2

    Create a virtual environment

    Navigate to your project folder and run python -m venv env to create an isolated environment.

    Tip: A dedicated folder like env keeps dependencies organized.
  3. 3

    Activate the environment

    Activate the virtual environment to ensure subsequent installs stay local to this project.

    Tip: Windows uses env\\Scripts\\activate; macOS/Linux uses source env/bin/activate.
  4. 4

    Upgrade pip inside the env

    With the environment active, upgrade pip to the latest compatible version to maximize compatibility and features.

    Tip: Using the isolated pip prevents system-wide changes.
  5. 5

    Install a package

    Run pip install <package-name> to add a dependency to your project.

    Tip: Specify a version if you need reproducibility, e.g., package==1.2.3.
  6. 6

    Install from a requirements file

    If your project uses multiple dependencies, install them all with pip install -r requirements.txt.

    Tip: Keep requirements.txt under version control for consistency.
  7. 7

    List installed packages

    Check what’s installed with pip list and examine package details with pip show.

    Tip: Use pip list --format=columns for readability.
  8. 8

    Deactivate the environment

    When finished, run deactivate to return to the system Python.

    Tip: Deactivation prevents accidental global installations.
Pro Tip: Always use a per-project virtual environment to avoid conflicts.
Warning: Do not install packages globally unless you truly understand the impact.
Note: Use requirements.txt to capture exact versions for reproducibility.

Got Questions?

What is pip and how does it relate to Python?

Pip is the Python package installer that lets you fetch and install packages from PyPI or other sources. It manages dependencies and can install specific versions.

Pip is the Python package installer that fetches and installs packages from PyPI, handling dependencies.

How do I install pip on Windows, macOS, or Linux?

On most systems, Python includes pip. If missing, run python -m ensurepip or use your package manager to install python-pip. Then verify with pip --version.

Pip usually comes with Python. If missing, use ensurepip to install it.

Why do I get 'command not found: pip'?

This usually means Python or pip isn’t on your PATH. Reinstall Python with 'Add to PATH' or adjust your system PATH to include the Scripts/ or bin/ folder.

Pip isn't on your PATH; add Python's Scripts folder to PATH or reinstall with PATH option.

Can I install multiple packages at once?

Yes. You can install multiple packages in one command (e.g., pip install package1 package2) or use a requirements.txt file for reproducibility.

You can install several packages at once or use a requirements file for consistency.

How do I install from a requirements.txt file?

Create a requirements.txt with versions and run pip install -r requirements.txt. This locks the environment for all collaborators.

Use pip install -r requirements.txt to install all declared dependencies.

Watch Video

Main Points

  • Set up a virtual environment for each project.
  • Pin versions to ensure reproducible installs.
  • Use requirements.txt for consistent dependencies.
  • Keep pip updated to avoid compatibility issues.
Infographic showing a 3-step pip install workflow
Pip Install Workflow

Related Articles