PIP is the standard package-management tool commonly used to install and manage Python packages. It allows developers to install packages, upgrade them, remove them, and manage project dependencies.
PIP is a package installer for Python. It can install packages from package indexes and other supported sources.
For example:
pip install requests
This command asks PIP to install the requests package.
You can check whether PIP is available by displaying its version.
pip --version
The exact version and installation path depend on your system.
The basic syntax for installing a package is:
pip install package_name
For example:
pip install requests
After installation, the package can be imported into a Python program.
import requests
You can request a particular package version using ==.
pip install requests==2.32.3
The package manager will attempt to install that specified version if it is available and compatible with the environment.
The --upgrade option tells PIP to upgrade a package.
pip install --upgrade requests
PIP checks the available package information and installs a newer compatible version when appropriate.
The uninstall command removes an installed package.
pip uninstall requests
PIP normally asks for confirmation before removing the package.
Use the list command to display packages installed in the
current Python environment.
pip list
The show command displays information about an installed package.
pip show requests
It can display information such as the package version, location and dependencies.
The freeze command outputs installed packages in a
requirements-style format.
pip freeze
The output can be saved to a file.
pip freeze > requirements.txt
A requirements.txt file commonly contains the dependencies
required by a Python project.
Example:
requests==2.32.3
Flask==3.1.0
numpy==2.2.0
Another environment can install the listed dependencies using:
pip install -r requirements.txt
The -r option tells PIP to read package requirements from a file.
pip install -r requirements.txt
This is especially useful when setting up an existing Python project on another computer or environment.
Instead of calling pip directly, you can run PIP through a
specific Python interpreter.
python -m pip --version
For example:
python -m pip install requests
This can be useful when a system has multiple Python installations.
On some systems, the PIP command associated with Python 3 may be named
pip3.
pip3 --version
You may also use:
python3 -m pip --version
The exact command depends on the operating system and Python installation.
Older PIP tutorials sometimes show commands such as:
pip search package_name
pip search is no longer
available. For finding packages, use the Python Package Index website or
another package discovery method instead.
On systems where you do not have permission to install packages globally,
you can use the --user option where supported.
python -m pip install --user requests
This installs the package for the current user rather than system-wide.
PIP is commonly used inside virtual environments. A virtual environment keeps a project's packages separate from packages installed for other projects.
Create a virtual environment:
python -m venv myenv
After activating the environment, PIP installs packages into that environment.
Flask is a popular Python web framework that can be installed with PIP.
pip install flask
After installation, it can be imported in a Python program:
from flask import Flask
NumPy is widely used for numerical and scientific computing.
pip install numpy
Then:
import numpy as np
numbers = np.array([1, 2, 3])
print(numbers)
Multiple packages can be installed in one command.
pip install requests flask numpy
PIP resolves and installs the requested packages and their required dependencies.
A package can depend on other packages. These are called dependencies.
When a package declares dependencies, PIP can install the required dependencies as part of the installation process.
pip install some_package
The exact dependencies depend on the package and version being installed.
PIP itself can be upgraded using PIP.
python -m pip install --upgrade pip
Using python -m pip associates the command with the selected
Python interpreter.
| Command | Purpose |
|---|---|
pip --version |
Show PIP version |
pip install package |
Install a package |
pip uninstall package |
Remove a package |
pip list |
List installed packages |
pip show package |
Show package information |
pip freeze |
Show installed packages in requirements format |
pip install -r requirements.txt |
Install requirements from a file |
pip install --upgrade package |
Upgrade a package |
python -m pip when you want to clearly target a particular Python interpreter.requirements.txt file when appropriate.pip install installs packages.pip uninstall removes packages.pip list displays installed packages.pip show displays package information.pip freeze displays installed packages in requirements format.requirements.txt can document project dependencies.python -m pip can help target a particular Python interpreter.Question: Which command is commonly used to install a Python package?