Error running 'pip install': "ImportError: No module named pip"
The crux of ImportError: No module named pip
is that pip
is absent in your system. Fix it with:
For the Python 3 users out there, replace the last part with python3
. This nifty command fetches the get-pip.py
script and runs it, giving your system the super power of pip
for package management.
Check your pip installation
Post running the command, you will see a 'Collecting pip' message, your ticket to the successful installation confirmation party. Inspect further with pip --version
or, for Python 3 users, pip3 --version
.
Keep Python updated or install from scratch
Ensure your version of Python is the latest and greatest:
- On Linux:
sudo apt-get update && sudo apt-get upgrade python3
- On macOS with Homebrew:
brew update && brew upgrade python
If you are craving a fresh Python install on macOS with pip included, cook it up with this recipe:
Virtual environment etiquette
Always say "activate your virtual environment, please" before wielding any pip installation commands:
Remember, pip
installs within the active environment like a polite house guest, ensuring the sanctity of your project's isolation.
Python and pip version mix-and-match
You'll want to match the right version of pip with your Python. For Python's 2.x fans club, use:
For those aboard Python 3.x spaceship, signal this command:
If you are living life on the edge with Python 2.7
, don't shy away from:
Didn't pip install work? Let's troubleshoot
If pip
installation is throwing tantrums, fear not! The user-friendly easy_install
is ready for your call:
It's good housekeeping to uninstall any old versions of pip before installing a new one, because nobody likes a cluttered toolbox:
Common pitfalls and how to avoid them
Monsters under the ImportError bed include:
- Python version: Are you using the right version for your requirements?
- Environment: Is it the right environment, which might already have
pip
installed?
Speaking in tongues: the right pip command
When dealing with polyglot systems where multiple Python versions speak different dialects, be very specific:
This ensures you're speaking to pip
from Python 3.8, and not linguistically confusing your system.
Was this article helpful?