PythonPython Environment and Development ToolsPython package management

What is pip in Python?

Question 22 of 24 · Updated

On this page

pip is Python's widely used package installer. It installs and manages Python distribution packages from package indexes, local files and other supported sources. It can also inspect installed packages, check dependency consistency and uninstall packages.

For example, an application that needs an HTTP client may use a third-party distribution such as requests rather than implementing HTTP handling from scratch. pip obtains and installs that distribution and resolves its declared dependencies.

Python itself runs the application; pip prepares the packages that the application can import.

1. Why do Python developers use pip?#

Python provides a standard library, including modules such as math, json, pathlib and datetime. These modules normally come with the interpreter and do not need separate installation through pip.

Third-party packages extend Python with additional functionality. Examples include NumPy for numerical computing, Django for web applications and pytest for testing.

pip gives developers a consistent way to obtain these distributions and install them into a selected Python environment.

TaskTypical command
Check pip availabilitypython -m pip --version
Install a distributionpython -m pip install requests
Install a particular versionpython -m pip install "requests==2.32.3"
Inspect a distributionpython -m pip show requests
List installed distributionspython -m pip list
Check dependency consistencypython -m pip check
Record installed versionspython -m pip freeze
Remove a distributionpython -m pip uninstall requests

The pinned version above is an illustrative example of requirement syntax, not a recommendation about the newest or safest version. Choose a compatible and appropriately reviewed version for your actual project.

The installation commands that name requests require access to a trusted package source or an approved local artifact. The offline example later in this article demonstrates the same installation mechanism without contacting a public package index.

2. Is pip included with Python?#

Many standard Python distributions include pip, or provide the standard-library ensurepip module to bootstrap it. Some operating-system distributions package pip separately or restrict changes to their system-managed Python installations.

Check the pip associated with your intended interpreter:

BASH
python -m pip --version

On the locally tested Python 3.13.5 environment, the output identified pip 25.1.1, its installation path and Python 3.13. Your output will depend on the installed release and environment.

On systems where python3 is the Python command, use python3 -m pip instead. On Windows, an available Python launcher can also invoke pip with py -m pip.

If pip is not available, consult the instructions for your Python distribution. On a standard installation that provides ensurepip, a virtual environment can normally bootstrap pip without contacting a package index. Do not use untrusted bootstrap scripts or attempt to modify operating-system-managed Python packages simply to make pip available.

3. Why use python -m pip instead of pip?#

A computer may contain several Python installations. A bare pip command can refer to an installer associated with a different interpreter than the one running your application.

The following commands explicitly use the same interpreter:

BASH
python -m pip --version python -c "import sys; print(sys.executable)"

The first shows pip's version and installation path. The second identifies the actual executable selected by python.

Using python -m pip reduces ambiguity because Python runs the pip module in the selected interpreter's environment. It is especially useful when diagnosing an import failure in an editor, CI runner or virtual environment.

It does not guarantee that every subsequent application command selects the same interpreter. Check the editor and runtime configuration as well.

4. How pip fits into the Python packaging ecosystem#

ComponentResponsibility
Python interpreterExecutes Python code
pipResolves and installs Python distribution packages and manages installed distributions
PyPIPublic package index that hosts distribution metadata and downloadable artifacts
Virtual environmentIsolates a project's Python packages
Build backendProduces distribution artifacts from a project's source
Dependency specification or lock workflowRecords the project's requirements and, where supported, resolved versions

PyPI stands for the Python Package Index. It is pip's default index in an ordinary configuration, but pip can also use a private index, local wheel directory or other supported source.

The name used to install a distribution need not equal the name used to import a module. For example, the Pillow distribution exposes the PIL import package. A distribution can also provide multiple import packages or no import package at all, such as a metadata-only distribution.

Thus pip list reports installed distributions, not an exhaustive list of names that can be imported.

5. What happens when pip installs a package?#

Conceptually, a command such as python -m pip install requests follows these stages:

Requested package and version constraints
                    |
                    v
Discover candidate distributions from configured sources
                    |
                    v
Resolve dependencies and compatible versions
                    |
                    v
Obtain suitable wheels or build wheels from source
                    |
                    v
Install files and distribution metadata into the target
                    |
                    v
Report success or an installation error

The resolver considers constraints from the user's requirements and package metadata. Compatibility can depend on the Python version, operating system, processor architecture and available distribution artifacts.

pip may need to examine several candidates before finding a compatible set. If constraints cannot be satisfied, installation may fail rather than selecting arbitrary incompatible versions.

This is a conceptual overview: individual operations can overlap, and exact behaviour depends on the pip version, package formats, installed packages and command options. Resolving a new request is not a guarantee that every unrelated pre-existing package remains compatible; run pip check and application tests as appropriate.

6. What are wheels and source distributions?#

A wheel is a built Python distribution format, usually stored in a file ending in .whl. It contains installable files and metadata. A compatible wheel generally avoids building the package from its original source during installation.

A source distribution (sdist), commonly a .tar.gz archive, contains source material needed to build the package. When an appropriate wheel is unavailable, pip can use a package's build backend to build a wheel, subject to available build dependencies and system tooling.

For packages containing native extensions, compatibility can depend on platform and Python ABI tags. An sdist build may also require a compiler, headers or external libraries.

Do not assume that pip installs arbitrary system-level libraries or operating-system packages. Those dependencies may require the operating system's package manager or another approved tool.

7. Practical example: install a package into an isolated environment#

Create an environment in a new project directory using a supported Python 3 interpreter:

BASH
python -m venv .venv

On macOS or Linux, the environment's interpreter is typically .venv/bin/python. On Windows, it is typically .venv\Scripts\python.exe.

You can invoke that interpreter directly, without activating the environment.

For a typical online installation on macOS or Linux:

BASH
.venv/bin/python -m pip install requests

This example requires a configured package source and network access if the necessary artifacts are not available locally. On Windows, substitute the environment's Windows executable path.

The earlier environment lessons explain how to create and activate virtual environments in detail. The key point here is that pip's installation target should be the interpreter your application actually uses.

Offline installation and dependency resolution#

For a controlled local test, two small wheel artifacts were created specifically for this lesson:

  • lesson-demo, version 1.0, exposing a lesson_demo import package with a greet function.
  • lesson-helper, version 1.0, declared as a required dependency of lesson-demo.

These are local test fixtures, not packages that readers should look up on PyPI. Suppose the two approved wheel files have already been placed in a directory named wheels:

wheels/
    lesson_demo-1.0-py3-none-any.whl
    lesson_helper-1.0-py3-none-any.whl

Install the demonstration distribution using only that local source:

BASH
.venv/bin/python -m pip install --no-index --find-links wheels lesson-demo==1.0

Relevant output from the offline test:

Successfully installed lesson-demo-1.0 lesson-helper-1.0

pip selected both the requested distribution and its declared dependency. The --no-index option disables package index lookup, while --find-links makes the supplied local artifact directory available to the installer. This is an appropriate technique for an approved offline wheelhouse; it is not a general security sandbox.

Verify the installed module:

BASH
.venv/bin/python -c "from lesson_demo import greet; print(greet())"

Output:

Hello from pip!

The example demonstrates that pip installed distribution files which the environment's interpreter could import. Merely installing packages does not automatically run your application.

8. How do you inspect dependencies after installation?#

The command below displays metadata about the installed demonstration distribution:

BASH
.venv/bin/python -m pip show lesson-demo

Selected output:

Name: lesson-demo
Version: 1.0
Requires: lesson-helper

The Requires field identifies a dependency named by the distribution's metadata. The full output also includes its installation location and other available metadata.

Check whether installed distributions have compatible declared dependencies:

BASH
.venv/bin/python -m pip check

Output in the isolated test:

No broken requirements found.

A successful dependency check is not a functional test or a vulnerability scan. It only checks the installed distribution requirements according to pip's validation rules. Continue to run the application's tests and appropriate security checks.

9. Does pip guarantee reproducible installations?#

No. A command such as pip install requests does not specify one exact version. Different installations may resolve to different compatible versions depending on package releases, Python compatibility and configured sources.

A requirements file can specify constraints for pip. For instance, a reviewed dependency specification might be installed with:

BASH
python -m pip install -r requirements.txt

The file must exist and contain suitable requirements for the project.

pip freeze can report installed versions in a requirements-style format:

BASH
.venv/bin/python -m pip freeze

For the locally tested environment, the relevant output was:

lesson-demo==1.0
lesson-helper==1.0

This is a snapshot of installed distributions, not necessarily a complete cross-platform lockfile or a description of which dependencies are direct. A repeatable build may also require a fixed Python version, compatible artifacts, package-source configuration, build constraints and hashes.

Use the project's documented dependency-management workflow rather than repeatedly installing unbounded packages into a shared global environment.

10. Common pip errors and what they mean#

ProblemLikely issueFirst troubleshooting step
No module named pippip is unavailable in the selected interpreterCheck the interpreter and distribution's pip support
No matching distribution foundWrong package name, incompatible version or unavailable sourceCheck requirement spelling, Python version and package availability
Dependency resolution failsIncompatible dependency constraintsReview conflicting requirements rather than forcing arbitrary versions
Failed building wheelMissing build support or incompatible sourceConsult the package's installation and compatibility documentation
ModuleNotFoundError after installationWrong interpreter or wrong import nameCompare sys.executable and pip show output
Externally managed environmentOS-managed Python restricts package modificationsCreate and use a project virtual environment

Error messages depend on the installed pip version and context. Diagnose the reported cause before changing the environment.

11. Security and maintainability#

A Python distribution can contain executable code, and installing from source may execute build backend code. Install packages only from trusted, approved sources and check the distribution's identity. Similar names can belong to unrelated publishers.

For shared projects:

  • Use isolated virtual environments instead of routinely installing into system Python.
  • Avoid running pip with unnecessary administrative privileges.
  • Review dependencies, versions and package sources before adoption.
  • Use reviewed locks or constraints and hashes where the project's requirements call for them.
  • Keep private-index credentials out of source code, terminal history and shared logs.
  • Be cautious when mixing public and private indexes; extra index sources can introduce dependency-confusion risks.
  • Test dependency updates and use appropriate vulnerability-management processes.

Package isolation is not a security sandbox. An installed package can exercise the permissions of the process that imports or executes it.

12. Frequently asked questions#

What does pip stand for?#

The name is commonly expanded as the recursive acronym "pip installs packages." Its important role is installing Python distribution packages.

Is pip part of Python's standard library?#

pip is a separately developed and distributed project. Many Python installations bundle or bootstrap it, and ensurepip is a standard-library module where available.

Is pip the same as PyPI?#

No. pip is the installer; PyPI is a public package index. pip can use other configured package sources.

Can pip install a package without internet access?#

Yes, provided compatible distribution artifacts and their dependencies are available locally. A local wheelhouse with --no-index and --find-links is one approach.

Does pip remove dependencies automatically when a package is uninstalled?#

Not generally. Uninstalling one distribution does not automatically remove every dependency that was installed alongside it, because other packages may require those dependencies.

Does pip install Python itself?#

No. pip normally operates within an existing Python installation. Use an appropriate interpreter installer or version manager to obtain a different Python version.

Interview-ready answer#

pip is Python's widely used package installer. It installs Python distributions from PyPI, other configured indexes or local artifacts, resolves declared dependencies and provides commands to inspect, check and uninstall packages. It can install compatible wheels or build a wheel from source. Developers should normally use python -m pip with the intended interpreter inside a project virtual environment so dependencies are isolated and installation targets are clear. pip is not the Python interpreter, a package index or an operating-system sandbox.

Key takeaways#

  • pip installs Python distribution packages; Python executes code.
  • PyPI is a package index, not the installer.
  • Use the intended interpreter's python -m pip command.
  • Package names and import names can differ.
  • Use dependency specifications, trusted sources and isolated environments for reliable development.

Official references#

Verification note: The local tests used Python 3.13.5 and pip 25.1.1 inside a temporary virtual environment. Two locally generated wheel fixtures were installed without a network connection, including automatic dependency installation. Import, pip list, pip show, pip check, pip freeze and removal checks passed. Public-index downloads and Windows-specific workflows were not executed. Official reference links are provided under the authorised offline research exception; live documentation was not checked.

Related questions

Explore other topics:Forward Deployed EngineeringMachine LearningSQL: Structured Query LanguageAI System Design