Python 3
pip installation
Python package manager
Python tutorial
software development

How to install pip with Python 3?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

On most modern Python 3 installations, pip is already included, so the real task is usually checking whether the correct interpreter has a working pip. The safest approach is to ask Python 3 directly instead of relying on a standalone pip command that might point at a different installation.

Check Before Installing Anything

Start with the simplest test:

bash
python3 -m pip --version

If that command works, pip is already available for that Python 3 interpreter. You can then install packages safely with:

bash
python3 -m pip install requests

Using python3 -m pip matters because it ties the package command to a specific interpreter. On machines with multiple Python versions, that avoids a lot of confusion.

Use ensurepip If pip Is Missing

If Python 3 exists but the previous command fails, the first repair step is usually ensurepip, which bootstraps pip from the standard library when it is available.

bash
python3 -m ensurepip --upgrade
python3 -m pip install --upgrade pip

This is the cleanest fix on many systems because it uses the Python installation’s own bootstrap tools instead of a third-party download.

Platform-Specific Installation Paths

Sometimes the issue is not pip itself but how Python 3 was installed.

Windows

Use the official Python installer or the py launcher. After installation:

powershell
py -3 -m pip --version
py -3 -m pip install --upgrade pip

The py launcher is helpful on Windows because it selects the intended interpreter more reliably than guessing whether python or python3 exists on PATH.

macOS

If Python 3 came from Homebrew, pip is normally included already:

bash
brew install python
python3 -m pip --version

If you used the official installer, the same python3 -m pip pattern still applies.

Linux

Many Linux distributions package pip separately:

bash
sudo apt update
sudo apt install python3-pip

On Fedora-like systems:

bash
sudo dnf install python3-pip

When the OS provides python3-pip, it is often better to use that package than to force a manual bootstrap into the system interpreter.

Why python3 -m pip Should Be the Default

It is common to have several Python environments on one machine:

  • a system Python
  • a package-manager Python
  • 'pyenv versions'
  • virtual environments
  • editor-managed interpreters

That is why the following pair of commands is so useful:

bash
python3 -c "import sys; print(sys.executable)"
python3 -m pip --version

Together they tell you exactly which interpreter and package location you are modifying. That is much safer than running bare pip and hoping it points to the right place.

Prefer Virtual Environments for Project Work

If you are setting up packages for an application, installing into the global interpreter is rarely the best long-term choice. Create a virtual environment and use its pip instead:

bash
1python3 -m venv .venv
2source .venv/bin/activate
3python -m pip install --upgrade pip
4python -m pip install requests

Inside the virtual environment, python and pip both refer to the project-specific interpreter. That keeps dependencies isolated and avoids damaging system tooling.

When the pip Command Exists but Is Wrong

Sometimes python3 -m pip works but the plain pip command does not, or it points to another Python version. In that situation, you do not necessarily need to fix the shell immediately. You can keep using:

bash
python3 -m pip install package_name

That command is explicit and reliable even if PATH contains several different pip executables.

Last Resort Options

If ensurepip is unavailable and the operating system package manager is not an option, a bootstrap script can be a fallback. That should be a last resort, though, because it bypasses normal system packaging conventions and makes interpreter ownership less clear.

In everyday Python 3 setups, ensurepip, the official installer, or the OS package manager is usually the better answer.

Common Pitfalls

  • Trying to “install pip” when python3 -m pip already works for the interpreter you care about.
  • Running bare pip and accidentally modifying a different Python installation.
  • Installing packages into the system interpreter when a virtual environment would be safer.
  • Assuming a missing pip shell command means the interpreter itself lacks pip.
  • Reaching for fallback bootstrap methods before checking ensurepip or the OS package manager.

Summary

  • First test python3 -m pip --version before installing anything.
  • If pip is missing, try python3 -m ensurepip --upgrade.
  • On Linux, the package manager often provides python3-pip directly.
  • Use python3 -m pip to keep package installs tied to the correct interpreter.
  • For project work, prefer a virtual environment instead of the global Python installation.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.