—
Python includes a large standard library, but real-world projects often require additional packages for web development, automation, data analysis, networking, machine learning, APIs, and many other tasks.
This is where pip is used.
pip is the standard package installer for Python. It can install packages from the Python Package Index (PyPI) and other supported package sources.
You may also encounter the command pip3, particularly on Linux systems where it is used to explicitly refer to the pip installation associated with Python 3.
A reliable way to run pip for a specific Python interpreter is:
python3 -m pip --version
and to install a package:
python3 -m pip install package-name
This guide explains how pip3 works, how to install and manage Python packages, how to use virtual environments, and how to troubleshoot common problems safely.

—
Understanding pip and pip3
pip is a Python package-management tool used to install and manage packages that are not necessarily part of Python’s standard library.
Common examples include:
- requests
- Flask
- Django
- pandas
- NumPy
- Paramiko
- FastAPI
- boto3
What Is PyPI?
The Python Package Index, commonly called PyPI, is the primary public repository used for distributing Python packages.
When you run:
python3 -m pip install requests
pip normally searches the configured package index, resolves compatible dependencies, downloads appropriate distributions, and installs them into the selected Python environment.
Packages may be distributed in forms such as:
- Wheel files
- Source distributions
Check Which pip You Are Using
Before installing anything, check the command being used.
pip3 --version
Example:
pip 25.x from /path/to/site-packages/pip (python 3.x)
You can also check:
python3 -m pip --version
Where Are Packages Installed?
The installation location depends on the environment.
Packages may be installed into:
- A virtual environment
- A user-specific Python location
- A Python installation managed outside the operating system
- A system-managed environment, subject to operating-system restrictions
For project development, a virtual environment is usually the safest and cleanest choice.
—
Installing and Verifying pip
The installation process differs between operating systems.
Ubuntu and Debian
First check whether Python is installed:
python3 --version
Check pip:
python3 -m pip --version
If pip is not available and you are using Ubuntu or Debian packages, you can install the distribution-provided package:
sudo apt update
sudo apt install python3-pip
Verify:
python3 -m pip --version
For virtual environments, you may also need:
sudo apt install python3-venv
macOS
If Python was installed using Homebrew, verify it with:
python3 --version
python3 -m pip --version
If Python is not installed through Homebrew:
brew install python
Then verify:
python3 -m pip --version
Windows
Install a current supported Python 3 release from the official Python distribution or another trusted Python distribution appropriate for your environment.
Verify Python:
py --version
Verify pip:
py -m pip --version
On systems where python is configured correctly, you can also use:
python -m pip --version
—
Essential pip Commands
Once pip is available, package management becomes straightforward.
Install a Package
For example, install requests:
python3 -m pip install requests
Install a Specific Version
You can pin a package to a particular version:
python3 -m pip install requests==2.32.5
This is useful when:
- An application requires a specific version
- A newer release introduces compatibility problems
- You need reproducible environments
Upgrade a Package
python3 -m pip install --upgrade requests
Upgrade pip
Inside an environment where pip itself is managed by that Python installation:
python3 -m pip install --upgrade pip
Uninstall a Package
python3 -m pip uninstall requests
pip will ask for confirmation before removing the package.
List Installed Packages
python3 -m pip list
Example:
Package Version
----------- -------
pip 25.x
requests 2.x
urllib3 2.x
Show Package Information
python3 -m pip show requests
This can display information such as:
- Package name
- Version
- Installation location
- Dependencies
- Packages that require it
Check for Outdated Packages
python3 -m pip list --outdated
Check Installed Dependency Compatibility
python3 -m pip check
This checks whether installed packages have compatible dependencies.
Export Installed Packages
python3 -m pip freeze > requirements.txt
Example file:
requests==2.x.x
urllib3==2.x.x
certifi==20xx.x.x
Install From requirements.txt
python3 -m pip install -r requirements.txt
—
Using pip With Virtual Environments
A virtual environment creates an isolated Python environment for a project.
This is one of the most important concepts for safe Python package management.
Suppose you have two applications:
- Application A requires one version of a library.
- Application B requires a different version.
Installing everything globally can create conflicts.
Virtual environments isolate those dependencies.

Step 1 — Create a Project Directory
mkdir my-python-project
cd my-python-project
Step 2 — Create the Virtual Environment
python3 -m venv .venv
This creates a .venv directory containing the isolated environment.
Step 3 — Activate It on Linux or macOS
source .venv/bin/activate
Your shell may now show something similar to:
(.venv) user@server:~/my-python-project$
Activate It on Windows PowerShell
..venvScriptsActivate.ps1
Step 4 — Verify the Environment
python -m pip --version
The displayed path should point toward the virtual environment.
Step 5 — Install a Package
python -m pip install flask
The package is installed inside the active virtual environment.
Step 6 — View Installed Packages
python -m pip list
Step 7 — Save Dependencies
python -m pip freeze > requirements.txt
Step 8 — Deactivate
deactivate
Complete Virtual Environment Example

—
pip, pip3 and python -m pip
Older tutorials often describe pip and pip3 as if they always represent different Python generations.
That is no longer a reliable assumption.
| Command | Typical Meaning | Recommendation |
|---|---|---|
pip |
pip associated with a configured Python installation | Verify before use |
pip3 |
Often pip associated with Python 3 | Common on Linux |
python3 -m pip |
Run pip using the selected Python 3 interpreter | Very clear on Linux/macOS |
python -m pip |
Run pip using the current python interpreter |
Excellent inside a virtual environment |
py -m pip |
Run pip through the Python Launcher | Useful on Windows |
Check before assuming:
pip --version
pip3 --version
python3 -m pip --version
—
Troubleshooting Common pip Problems
Most pip problems fall into a few common categories.
Problem 1 — pip3 Command Not Found
Example:
pip3: command not found
First check Python:
python3 --version
Then:
python3 -m pip --version
On Ubuntu or Debian, if the distribution package is required:
sudo apt update
sudo apt install python3-pip
Problem 2 — Externally Managed Environment
On some modern Linux distributions you may encounter an error similar to:
error: externally-managed-environment
This protection helps prevent pip from interfering with packages managed by the operating system.
For a project, create a virtual environment:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install requests
Problem 3 — Permission Denied
A permission error may mean that you are trying to write to a location managed by another user or by the operating system.
For projects, prefer:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install package-name
Problem 4 — Wrong Python Environment
You install a package but Python cannot import it.
Example:
ModuleNotFoundError: No module named 'requests'
Check:
python3 --version
python3 -m pip --version
python3 -m pip show requests
The package may have been installed into a different Python environment.
Problem 5 — Dependency Conflicts
Run:
python3 -m pip check
If several projects require incompatible dependency versions, isolate them with separate virtual environments.
Problem 6 — Proxy Problems
Corporate networks may require HTTP or HTTPS proxy configuration.
Example environment variables on Linux:
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
pip Troubleshooting Workflow
1Check Python2Check pip3Identify Environment4Check Virtual Environment5Check Package Name6Check Network7Check Proxy8Check Certificate Trust9Check Permissions10Check Dependencies11Install Package12Verify Package
—
Security and Real-World Best Practices
pip makes installing software extremely easy.
That convenience also means package installation should be treated as a software supply-chain activity.
Use Virtual Environments
Keep project dependencies isolated.
Verify Package Names
Check package names carefully before installation.
A malicious package may intentionally use a name similar to a popular legitimate project.
Prefer Trusted Package Sources
PyPI is the primary public Python package index, but package publishers remain responsible for the software they upload.
Before using an unfamiliar dependency, review:
- Package name
- Publisher or project information
- Project documentation
- Release history
- Source repository where available
- Security information
- Maintenance activity
Pin Versions Where Reproducibility Matters
For example:
requests==2.32.5
flask==3.1.2
Version pinning can improve reproducibility, although dependencies still need regular maintenance and security updates.
Use Hash Checking for Stronger Reproducibility
pip requirements files can include package hashes.
Conceptually:
package-name==version
--hash=sha256:expected-package-hash
Then installations can require matching hashes:
python -m pip install --require-hashes -r requirements.txt
Do Not Blindly Upgrade Production Dependencies
Running a broad package upgrade can introduce:
- API changes
- Dependency conflicts
- Changed behavior
- Application incompatibility
Test dependency changes before production deployment.
Keep Development and Production Reproducible
Maintain dependency information in version control where appropriate.
Examples include:
requirements.txt
pyproject.toml
- Lock files produced by dependency-management tools
Common Real-World Uses
| Area | Example Packages |
|---|---|
| Data Analysis | NumPy, pandas, Matplotlib |
| Web Development | Flask, Django, FastAPI |
| Automation | requests, Paramiko |
| AWS Automation | boto3 |
| Machine Learning | scikit-learn and framework-specific packages |
| Testing | pytest |
| Network Automation | Netmiko, NAPALM |
Network Automation Example
A network engineer may create an isolated environment:
python3 -m venv network-lab
source network-lab/bin/activate
python -m pip install netmiko
Verify:
python -m pip show netmiko
After completing the lab:
deactivate
—
Summary
pip is one of the most important tools in the Python ecosystem.
It allows developers, system administrators, network engineers, DevOps engineers, and security professionals to install and manage Python packages efficiently.
The most important points to remember are:
pip3commonly refers to pip for Python 3, but command naming varies between systems.- Do not assume that
pipmeans Python 2. - Use
python3 -m pipwhen you want to explicitly associate pip with a particular Python 3 interpreter. - Use
python -m pipinside an activated virtual environment. - Use virtual environments for project dependencies.
- Avoid routinely installing project packages into an OS-managed Python environment.
- Avoid using
sudo pip installas a general solution. - Use
pip list,pip show, andpip checkfor troubleshooting. - Record dependencies when reproducibility matters.
- Verify package names and sources before installing unfamiliar software.
- Treat Python dependencies as part of the software supply chain.
- Test dependency upgrades before introducing them into production.
—
Useful Links and References
SanchitGurukul Static Resources
Related SanchitGurukul Articles
Official External References
Your feedback matters
Was this post helpful?
Discussion
0 approved comments
No approved comments yet. You can start the discussion below.
Leave a Comment
No login is required. Name and email are used for moderation/security. Your email is never displayed publicly. All comments require administrator approval.
Discover more from SanchitGurukul
Subscribe to get the latest posts sent to your email.