📘 Post

pip3: A Comprehensive Guide

10/21/2026 By Sanchit Agrawal 12 min read 👁 850 views

—
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:

CommandLINUX
python3 -m pip --version

and to install a package:

CommandLINUX
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.

pip3

—

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:

CommandLINUX
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.

CommandLINUX
pip3 --version

Example:

Output / Result
pip 25.x from /path/to/site-packages/pip (python 3.x)

You can also check:

CommandLINUX
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:

CommandLINUX
python3 --version

Check pip:

CommandLINUX
python3 -m pip --version

If pip is not available and you are using Ubuntu or Debian packages, you can install the distribution-provided package:

CommandLINUX
sudo apt update
sudo apt install python3-pip

Verify:

CommandLINUX
python3 -m pip --version

For virtual environments, you may also need:

CommandLINUX
sudo apt install python3-venv

macOS

If Python was installed using Homebrew, verify it with:

CommandLINUX
python3 --version
python3 -m pip --version

If Python is not installed through Homebrew:

CommandLINUX
brew install python

Then verify:

CommandLINUX
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:

CommandPOWERSHELL
py --version

Verify pip:

CommandPOWERSHELL
py -m pip --version

On systems where python is configured correctly, you can also use:

CommandPOWERSHELL
python -m pip --version

—

Essential pip Commands

Once pip is available, package management becomes straightforward.

Install a Package

For example, install requests:

CommandLINUX
python3 -m pip install requests

Install a Specific Version

You can pin a package to a particular version:

CommandLINUX
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

CommandLINUX
python3 -m pip install --upgrade requests

Upgrade pip

Inside an environment where pip itself is managed by that Python installation:

CommandLINUX
python3 -m pip install --upgrade pip

Uninstall a Package

CommandLINUX
python3 -m pip uninstall requests

pip will ask for confirmation before removing the package.

List Installed Packages

CommandLINUX
python3 -m pip list

Example:

Output / Result
Package     Version
----------- -------
pip         25.x
requests    2.x
urllib3     2.x

Show Package Information

CommandLINUX
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

CommandLINUX
python3 -m pip list --outdated

Check Installed Dependency Compatibility

CommandLINUX
python3 -m pip check

This checks whether installed packages have compatible dependencies.

Export Installed Packages

CommandLINUX
python3 -m pip freeze > requirements.txt

Example file:

Output / Result
requests==2.x.x
urllib3==2.x.x
certifi==20xx.x.x

Install From requirements.txt

CommandLINUX
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.

global python vs project vir env

Step 1 — Create a Project Directory

CommandLINUX
mkdir my-python-project
cd my-python-project

Step 2 — Create the Virtual Environment

CommandLINUX
python3 -m venv .venv

This creates a .venv directory containing the isolated environment.

Step 3 — Activate It on Linux or macOS

CommandLINUX
source .venv/bin/activate

Your shell may now show something similar to:

Output / Result
(.venv) user@server:~/my-python-project$

Activate It on Windows PowerShell

CommandPOWERSHELL
..venvScriptsActivate.ps1

Step 4 — Verify the Environment

CommandLINUX
python -m pip --version

The displayed path should point toward the virtual environment.

Step 5 — Install a Package

CommandLINUX
python -m pip install flask

The package is installed inside the active virtual environment.

Step 6 — View Installed Packages

CommandLINUX
python -m pip list

Step 7 — Save Dependencies

CommandLINUX
python -m pip freeze > requirements.txt

Step 8 — Deactivate

CommandLINUX
deactivate

Complete Virtual Environment Example

python3 vir envir workflow

—

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:

CommandLINUX
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:

Output / Result
pip3: command not found

First check Python:

CommandLINUX
python3 --version

Then:

CommandLINUX
python3 -m pip --version

On Ubuntu or Debian, if the distribution package is required:

CommandLINUX
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:

Output / Result
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:

CommandLINUX
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:

CommandLINUX
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:

Output / Result
ModuleNotFoundError: No module named 'requests'

Check:

CommandLINUX
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:

CommandLINUX
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:

ConfigurationLINUX
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080

pip Troubleshooting Workflow

pip Installation Troubleshooting Workflow

1Check Python2Check pip3Identify Environment4Check Virtual Environment5Check Package Name6Check Network7Check Proxy8Check Certificate Trust9Check Permissions10Check Dependencies11Install Package12Verify Package

pip problems are easier to solve when Python environment, permissions, dependencies, and connectivity are checked systematically.

—

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:

ConfigurationTEXT
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:

ConfigurationTEXT
package-name==version
    --hash=sha256:expected-package-hash

Then installations can require matching hashes:

CommandLINUX
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:

CommandLINUX
python3 -m venv network-lab
source network-lab/bin/activate
python -m pip install netmiko

Verify:

CommandLINUX
python -m pip show netmiko

After completing the lab:

CommandLINUX
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:

  1. pip3 commonly refers to pip for Python 3, but command naming varies between systems.
  2. Do not assume that pip means Python 2.
  3. Use python3 -m pip when you want to explicitly associate pip with a particular Python 3 interpreter.
  4. Use python -m pip inside an activated virtual environment.
  5. Use virtual environments for project dependencies.
  6. Avoid routinely installing project packages into an OS-managed Python environment.
  7. Avoid using sudo pip install as a general solution.
  8. Use pip list, pip show, and pip check for troubleshooting.
  9. Record dependencies when reproducibility matters.
  10. Verify package names and sources before installing unfamiliar software.
  11. Treat Python dependencies as part of the software supply chain.
  12. Test dependency upgrades before introducing them into production.

—

SanchitGurukul Static Resources

Related SanchitGurukul Articles

Official External References

Disclaimer: This article may contain information that was accurate at the time of writing but could be outdated now. Please verify details with the latest vendor advisories or contact us at admin@sanchitgurukul.com.

Your feedback matters

Was this post helpful?

0 reactions

SanchitGurukul — Technology • Education • Innovation

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.

This field is not used to determine whether a comment is safe.

Plain text only. File uploads, scripts, executable code, abuse and spam are not accepted.


Discover more from SanchitGurukul

Subscribe to get the latest posts sent to your email.

Share this article

Help others find this guide.

Namaste! I’m SG Saarthi 👋Need help learning or finding something?

Discover more from SanchitGurukul

Subscribe now to keep reading and get access to the full archive.

Continue reading