Python
pip
pip3
package installation
Python 3

pip or pip3 to install packages for Python 3?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

If you want to install packages for Python 3, the most reliable answer is usually not "use pip" or "use pip3" in the abstract. The safest command is to invoke pip through the exact Python interpreter you mean, such as python3 -m pip install package-name or, on Windows, py -3 -m pip install package-name.

Why pip and pip3 Can Be Confusing

On some systems:

  • 'pip points to Python 3'
  • 'pip3 also points to Python 3'
  • both exist and are equivalent

On others:

  • 'pip may point to Python 2 in older setups'
  • 'pip3 points to Python 3'
  • shell path configuration changes which one you actually get

That is why people get conflicting advice. The command name alone is not the important part. The interpreter behind it is.

Use python -m pip

The most dependable pattern is:

bash
python3 -m pip install requests

Or on Windows:

bash
py -3 -m pip install requests

This guarantees that the pip module belonging to that Python interpreter performs the installation.

You can check what interpreter and installer you are using:

bash
python3 --version
python3 -m pip --version

That is much safer than guessing which standalone pip executable your shell will resolve.

When pip3 Is Fine

If your environment is clean and you know pip3 maps to the intended Python 3 installation, then this is perfectly acceptable:

bash
pip3 install requests

The problem is not that pip3 is wrong. The problem is that it is less explicit about which interpreter owns the installation.

Virtual Environments Make the Question Easier

Inside an activated virtual environment, plain pip is usually the correct command because it targets that environment.

Create and activate a virtual environment:

bash
python3 -m venv .venv
source .venv/bin/activate

Then install packages:

bash
pip install requests

Now pip is bound to the virtual environment, which is exactly what you want for project isolation.

Verify Where the Package Was Installed

If you are unsure whether the package went to the right interpreter, check it explicitly:

bash
python3 -m pip show requests
python3 -c "import requests; print(requests.__file__)"

That is often the fastest way to diagnose "I installed it, but import still fails" problems.

Avoid sudo When You Can

Global installs with sudo pip or sudo pip3 can create permission and environment problems. In most development workflows, prefer:

  • a virtual environment
  • user-level installs when appropriate
  • project-managed dependency files

For example:

bash
python3 -m pip install --user requests

That is still less ideal than a virtual environment for most projects, but it is safer than spraying packages into a system interpreter unnecessarily.

Common Pitfalls

  • Assuming pip always means Python 3 is unsafe on older or mixed installations.
  • Using pip3 is not wrong, but it still leaves room for path confusion if multiple Python 3 interpreters exist.
  • Installing with one interpreter and running code with another is one of the most common packaging mistakes.
  • Using sudo pip for normal development can damage system Python environments.
  • Forgetting to activate the virtual environment before installing often sends packages to the wrong place.

Summary

  • For Python 3, the most reliable command is usually python3 -m pip install package-name.
  • On Windows, py -3 -m pip is often the clearest form.
  • 'pip3 is fine when you know exactly what it points to.'
  • Inside an activated virtual environment, plain pip is normally correct.
  • When in doubt, check python -m pip --version to see which interpreter owns the installation.

Course illustration
Course illustration

All Rights Reserved.