How to Fix Linux pip vs pip3 Command Error
In this tutorial, you'll learn about How to Fix Linux pip vs pip3 Command Error. We cover key concepts, practical examples, and best practices.
You type pip and get command not found, or pip installs packages for Python 2 when you need Python 3 — the wrong pip version is installed or pip is missing entirely.
The Problem
pip: command not found
Or:
pip install requests
# Installs for Python 2, but you use Python 3
Step-by-Step Fix
Step 1: Check which Python version you use
python --version
python3 --version
If python points to Python 2 and python3 to Python 3, use pip3.
Step 2: Install pip for Python 3
sudo apt update
sudo apt install python3-pip
Step 3: Use python3 -m pip instead of pip3
This always uses the correct pip for Python 3:
# WRONG — may use wrong Python version
pip install requests
# RIGHT — always uses current Python's pip
python3 -m pip install requests
Step 4: Install a specific package for Python 3
python3 -m pip install requests
Or use pip3 explicitly:
pip3 install requests
Step 5: Create a virtual environment
# Create venv with Python 3
python3 -m venv myenv
# Activate
source myenv/bin/activate
# Now pip installs into the venv
pip install requests
Step 6: Install pip if missing (without apt)
For older systems:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
Step 7: Fix pip pointing to the wrong Python version
# Check current pip's Python
pip --version
# If it shows Python 2, use pip3 instead
pip3 --version
# Or reinstall pip for Python 3
sudo python3 -m pip install --upgrade --force-reinstall pip
Prevention Tips
- Always use
python3 -m pipinstead of barepip - Use virtual environments per project
- Set
pythonto Python 3 withsudo apt install python-is-python3 - Check Python version before installing packages
- Do not install system-wide packages unless necessary
Common Mistakes with pip python3
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists
These mistakes appear frequently in real-world LINUX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro