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.
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:
If that command works, pip is already available for that Python 3 interpreter. You can then install packages safely with:
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.
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:
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:
If you used the official installer, the same python3 -m pip pattern still applies.
Linux
Many Linux distributions package pip separately:
On Fedora-like systems:
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
- '
pyenvversions' - virtual environments
- editor-managed interpreters
That is why the following pair of commands is so useful:
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:
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:
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 pipalready works for the interpreter you care about. - Running bare
pipand accidentally modifying a different Python installation. - Installing packages into the system interpreter when a virtual environment would be safer.
- Assuming a missing
pipshell command means the interpreter itself lackspip. - Reaching for fallback bootstrap methods before checking
ensurepipor the OS package manager.
Summary
- First test
python3 -m pip --versionbefore installing anything. - If
pipis missing, trypython3 -m ensurepip --upgrade. - On Linux, the package manager often provides
python3-pipdirectly. - Use
python3 -m pipto keep package installs tied to the correct interpreter. - For project work, prefer a virtual environment instead of the global Python installation.
Related reading
- how to install pip with yum on EC2
- How to install psycopg2 with pip on Python?
- How to install python3 version of package via pip on Ubuntu?
- How to install Python 3.8 along with Python 3.9 in Arch Linux?
- How to install python modules without root access?
- How to install Python MySQLdb module using pip?
- How to install Python MySQLdb module using pip?
- How to install Python package from GitHub?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.