Pythonpip — Package Installer

pip — Package Installer

pip is Python's standard package installer. It downloads and installs libraries — anything from small utilities to large frameworks — so you can use them in your own code without writing them from scratch. pip has shipped bundled with Python since version 3.4, so on any modern Python install, it's already available via the pip (or pip3) command.

PyPI: Where Packages Come From

By default, pip downloads packages from the Python Package Index (PyPI), hosted at pypi.org. PyPI is a public registry where anyone can publish a package under a name and version number. When you run pip install requests, pip looks up requests on PyPI, resolves its dependencies, downloads the right files for your platform, and installs them into your environment.

Installing Packages

Bash
pip install requests

This installs the latest version of requests (and any packages it depends on) into your current Python environment.

Installing a Specific Version

Sometimes you need an exact version — to match a production environment, or because a newer release breaks your code. Pin the version with ==:

Bash
pip install requests==2.31.0
Upgrading and Uninstalling

To bring an already-installed package up to its latest version, use -U (short for --upgrade):

Bash
pip install -U requests
# equivalent, spelled out:
pip install --upgrade requests

To remove a package entirely:

Bash
pip uninstall requests
Listing Installed Packages

pip gives you two related but differently-formatted views of what's installed. pip list prints a friendly, human-readable table:

Bash
pip list

pip freeze, on the other hand, prints output in the exact package==version format that a requirements.txt file expects — making it the tool you use to snapshot an environment for reproduction elsewhere:

Bash
pip freeze
The requirements.txt Workflow

Most Python projects track their dependencies in a requirements.txt file. The typical workflow has two halves: capturing the current environment's package versions, and later reinstalling those exact versions somewhere else (a teammate's machine, a CI runner, a production server).

Bash
# Snapshot everything currently installed into requirements.txt
pip freeze > requirements.txt

# Later, on another machine, reproduce that exact set of packages
pip install -r requirements.txt

A typical requirements.txt file looks like this:

Bash
requests==2.31.0
flask==3.0.0
python-dotenv==1.0.0
Note
`pip freeze` captures every package in the current environment, including transitive dependencies you didn't install directly. For larger projects, many teams instead hand-maintain a `requirements.txt` (or use a tool like Poetry or pip-tools) listing only their direct dependencies, letting the tool resolve the rest.
Installing from GitHub or a Local Path

pip isn't limited to PyPI. You can install directly from a Git repository:

Bash
pip install git+https://github.com/user/repo.git

Or from a package sitting in a local directory — useful while developing your own library:

Bash
pip install ./my-local-package

# "editable" install: changes to the source are picked up
# immediately without reinstalling
pip install -e .

The -e (editable) flag is especially handy when you're actively developing a package alongside a project that depends on it — edits to the source take effect immediately, with no reinstall step.

Common pip Commands

Command

Description

pip install <package>

Install the latest version of a package

pip install <package>==<version>

Install a specific version

pip install -U <package>

Upgrade an already-installed package

pip uninstall <package>

Remove an installed package

pip list

Show installed packages in a readable table

pip freeze

Show installed packages in requirements.txt format

pip install -r requirements.txt

Install everything listed in a requirements file

pip install -e .

Install the current directory as an editable package

pip show <package>

Display metadata about an installed package

Tip
Always create and activate a virtual environment before running `pip install`. Without one, packages install into your global (or system) Python, which can quickly lead to version conflicts between unrelated projects. A virtual environment gives each project its own isolated set of installed packages.
Warning
Avoid running `pip install` with `sudo` to "fix" permission errors on your system Python. That installs packages system-wide, can conflict with packages your operating system depends on, and is almost always a sign you should be using a virtual environment instead.