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 PyYAMLpip broadly performs these steps:
- Identifies the requested distribution and any version constraint.
- Checks the selected package index, local sources, and its download cache.
- Finds versions compatible with the Python version, operating system, CPU architecture, and stated constraints.
- Resolves required dependencies.
- Downloads suitable distribution archives when they are not already cached locally.
- Uses an existing wheel or builds a wheel from a source distribution when necessary.
- 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 installnormally reports that the requirement is satisfied and leaves it in place. - If an archive is cached,
pipcan reuse it instead of downloading it again. - If it is neither installed nor cached,
pipdownloads 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 BOn 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
pipseparately from the Python interpreter. python -m venv .venvnormally bootstrapspipinto the new environment unless it is created with--without-pip.
Check the interpreter you plan to use:
python -m pip --versionIf 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 PyYAMLWindows PowerShell
py -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install PyYAMLActivation 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
| Question | pip | apt | dnf / yum |
|---|---|---|---|
| Main scope | Python distributions | Debian/Ubuntu operating-system packages | RPM-based operating-system packages |
| Typical source | PyPI or another Python package index | Distribution repositories | Distribution repositories |
| What it can install | Python modules, libraries, and Python CLI applications | Python, system libraries, services, applications, kernel packages | Python, system libraries, services, applications, kernel packages |
| Normal project destination | .venv/.../site-packages | System-managed paths such as /usr | System-managed paths such as /usr |
| Dependency authority | Python package metadata | Distribution package metadata and policy | Distribution package metadata and policy |
| Typical permissions | Normal user inside a virtual environment | Administrator/root for system changes | Administrator/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 pipto 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 updateapt 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-yamlThis installs the Debian/Ubuntu package and its dependencies into system-managed locations.
sudo apt upgradeThis 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 PyYAMLWithout --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 ETPyYAML is a third-party distribution:
python -m pip install PyYAMLimport yamlThe install name and import name differ. See Modules and Imports for why.
Choosing an Installation Tool
| Need | Suitable starting point |
|---|---|
| Dependencies for one Python project | Virtual environment plus pip |
| A Python command-line application isolated from projects | pipx |
| Software managed as part of a Linux host | apt or dnf, when the distribution provides it |
| Dependency resolution, lock files, environments, and project workflows together | A 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 PyYAMLTL;DR
pipdownloads 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-packagesdirectory. - Use a virtual environment for each application project.
- Use
python -m pipto target the same interpreter that will run the code. aptanddnfmanage the operating system;pipmanages Python distributions.apt updaterefreshes package metadata. It does not install updates.importloads installed code; it does not perform installation.- Avoid
sudo pipand do not bypass an externally managed Python without understanding the consequences.
Resources
- Install packages using
pipandvenv pip installreference- Python distribution package formats
- Python virtual environments
- Externally Managed Environments
- Debian
apt-getreference - DNF command reference
- Installing Python command-line tools with
pipx
Note: Commands and package-management behaviour were checked against current Python, pip, PyPA, Debian, and DNF documentation in July 2026.