pip installs Python distribution packages into a particular Python environment. It can retrieve a package from the Python Package Index (PyPI), another package index, a local directory, a version-control URL, or an archive.

For application projects, the normal destination is a virtual environment rather than the operating system’s Python installation.

What pip install Actually Does

For this command:

python -m pip install PyYAML

pip broadly performs these steps:

  1. Identifies the requested distribution and any version constraint.
  2. Checks the selected package index, local sources, and its download cache.
  3. Finds versions compatible with the Python version, operating system, CPU architecture, and stated constraints.
  4. Resolves required dependencies.
  5. Downloads suitable distribution archives when they are not already cached locally.
  6. Uses an existing wheel or builds a wheel from a source distribution when necessary.
  7. Installs the package files, metadata, and any command-line entry points into the active environment.
PyPI or another source

          │ download wheel/source if needed

       pip cache

          │ resolve and build

Python environment
├── site-packages/
│   ├── yaml/                    importable code
│   └── PyYAML-<version>.dist-info/  install metadata
└── bin/                         command-line scripts on macOS/Linux
    └── ...

On Windows, an environment’s command-line scripts normally go under Scripts\ instead of bin/.

Are the files already present?

It depends:

  • If the required version is already installed, pip install normally reports that the requirement is satisfied and leaves it in place.
  • If an archive is cached, pip can reuse it instead of downloading it again.
  • If it is neither installed nor cached, pip downloads it from the configured source.
  • A wheel is an installable ZIP archive containing package files and metadata. The installer places those files into the environment and can generate bytecode files.
  • A source distribution must first be built into a wheel. This step may compile native code and may require system compilers or development libraries.

So yes, pip places real files on disk. They remain there after the command exits and are available to that environment’s Python interpreter.

Why Use python -m pip?

python -m pip install PyYAML

-m pip tells the selected Python interpreter to run its pip module. A bare command such as pip install PyYAML may point to a different Python installation through the shell’s PATH.

The explicit form prevents a common situation:

pip installs into Python A
application runs with Python B
import yaml fails in Python B

On Windows, the Python Packaging guide commonly uses py -m pip.

Is pip Already Installed?

That depends on how Python was installed:

  • Current installers from python.org normally bootstrap pip.
  • A Linux distribution may package pip separately from the Python interpreter.
  • python -m venv .venv normally bootstraps pip into the new environment unless it is created with --without-pip.

Check the interpreter you plan to use:

python -m pip --version

If that command fails on a distribution-managed Python, follow the operating system’s instructions for installing pip or virtual-environment support. Do not download a random pip executable or assume that another pip command on PATH belongs to the same interpreter.

Use a Virtual Environment

A virtual environment gives a project its own interpreter context and site-packages directory.

macOS and Linux

python3 -m venv .venv
source .venv/bin/activate
python -m pip install PyYAML

Windows PowerShell

py -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install PyYAML

Activation places the environment’s executable directory earlier in PATH. It is a convenience, not magic; commands can also use the environment’s Python executable directly.

Check the result:

python -m pip show PyYAML
python -c "import yaml; print(yaml.__file__)"

The .venv directory is generated project state. Do not commit it to Git or move it between machines. Recreate it from the project’s dependency declarations.

pip Compared with apt, dnf, and yum

Questionpipaptdnf / yum
Main scopePython distributionsDebian/Ubuntu operating-system packagesRPM-based operating-system packages
Typical sourcePyPI or another Python package indexDistribution repositoriesDistribution repositories
What it can installPython modules, libraries, and Python CLI applicationsPython, system libraries, services, applications, kernel packagesPython, system libraries, services, applications, kernel packages
Normal project destination.venv/.../site-packagesSystem-managed paths such as /usrSystem-managed paths such as /usr
Dependency authorityPython package metadataDistribution package metadata and policyDistribution package metadata and policy
Typical permissionsNormal user inside a virtual environmentAdministrator/root for system changesAdministrator/root for system changes

The tools can package some of the same software, but they manage different inventories. A Linux distribution may offer PyYAML as an OS package, while PyPI offers it as a Python distribution.

Warning: Avoid using sudo pip to change the system Python. It can overwrite files or dependency versions expected by the operating system’s package manager.

Modern Linux distributions may mark their Python installation as externally managed. In that case, pip refuses to modify the global environment and directs the user to a virtual environment or a distribution package. The --break-system-packages override exists, but its name accurately describes the risk.

apt update Is Not pip install

These commands perform different actions:

sudo apt update

apt update downloads current package-index metadata. It tells APT which versions are available; it does not install or upgrade those packages.

sudo apt install python3-yaml

This installs the Debian/Ubuntu package and its dependencies into system-managed locations.

sudo apt upgrade

This upgrades installed OS packages where APT can do so under that command’s rules.

DNF uses commands such as dnf install, dnf check-update, and dnf upgrade. yum is the older RPM package manager and remains a compatibility command on some systems; follow the documentation for the distribution being managed.

pip does not have an equivalent pip update command:

python -m pip install --upgrade PyYAML

Without --upgrade, pip install normally keeps an already installed version that satisfies the requirement. With no version specified, it selects the latest compatible stable release available from its configured sources; pre-releases are excluded by default.

Standard Library or Third-Party Package?

Standard-library modules arrive with Python and need no pip install:

import json
import pathlib
import xml.etree.ElementTree as ET

PyYAML is a third-party distribution:

python -m pip install PyYAML
import yaml

The install name and import name differ. See Modules and Imports for why.

Choosing an Installation Tool

NeedSuitable starting point
Dependencies for one Python projectVirtual environment plus pip
A Python command-line application isolated from projectspipx
Software managed as part of a Linux hostapt or dnf, when the distribution provides it
Dependency resolution, lock files, environments, and project workflows togetherA higher-level Python project tool such as uv, Poetry, or PDM

pip is an installer, not a complete project workflow manager. Higher-level tools still work with Python distributions but add environment and dependency-management features.

Useful Inspection Commands

# Show the pip associated with this interpreter
python -m pip --version
 
# Show an installed distribution and its location
python -m pip show PyYAML
 
# List installed distributions
python -m pip list
 
# Preview resolution without installing
python -m pip install --dry-run PyYAML
 
# Remove a distribution from this environment
python -m pip uninstall PyYAML

TL;DR

  • pip downloads or reuses distribution archives, resolves dependencies, builds when needed, and installs files into a Python environment.
  • Installed importable code normally lives in that environment’s site-packages directory.
  • Use a virtual environment for each application project.
  • Use python -m pip to target the same interpreter that will run the code.
  • apt and dnf manage the operating system; pip manages Python distributions.
  • apt update refreshes package metadata. It does not install updates.
  • import loads installed code; it does not perform installation.
  • Avoid sudo pip and do not bypass an externally managed Python without understanding the consequences.

Resources

Note: Commands and package-management behaviour were checked against current Python, pip, PyPA, Debian, and DNF documentation in July 2026.