How can I Install pip for python 3.7 on Ubuntu 18?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
On Ubuntu 18.04, python3-pip installs pip for the system's default Python 3, which is usually Python 3.6, not Python 3.7. If you specifically need pip tied to python3.7, the safest approach is to make sure Python 3.7 and its support packages are present, then bootstrap pip for that interpreter directly.
Confirm Python 3.7 Exists First
Start by checking whether python3.7 is already installed:
If that command fails, install Python 3.7 first. On Ubuntu 18.04, many developers used the deadsnakes repository for newer Python builds:
The distutils package matters because older pip bootstrap methods often depend on it, and venv is useful if you want isolated environments afterward.
Install pip for Python 3.7
Once python3.7 is available, download the pip bootstrap script for Python 3.7 and run it with that interpreter:
If your environment requires elevated privileges for system-wide installation, use:
After installation, verify that the pip you are invoking belongs to Python 3.7:
Using python3.7 -m pip is the most reliable habit because it guarantees you are talking to the correct interpreter.
Install Packages the Right Way
Once pip is installed, prefer this style:
That is better than relying on a bare pip or pip3 command, because those names may point to a different Python installation on the same machine.
You can also upgrade pip itself this way:
And inspect installed packages:
Consider Using a Virtual Environment
If the goal is project work rather than system administration, create a virtual environment with Python 3.7 and install packages there:
This avoids mixing project dependencies into the global interpreter and makes the setup easier to reproduce.
Inside the virtual environment, python and pip point at the environment automatically, which reduces version confusion.
Troubleshooting Common Problems
If python3.7 -m pip still fails after bootstrapping, check that the installation path is on your environment or keep using the explicit interpreter form. The explicit form is usually enough and does not require shell alias changes.
If curl is unavailable, you can fetch the bootstrap script with wget instead:
If SSL or certificate errors appear during package installation, first upgrade pip and make sure system certificates are current. Those failures are usually network or trust-store problems, not Python 3.7 problems specifically.
Common Pitfalls
The biggest mistake is installing python3-pip and assuming it automatically attaches to Python 3.7. On Ubuntu 18.04, that package typically follows the default Python 3 interpreter.
Another common issue is using plain pip3 after installing multiple Python versions. The command may work, but it may install into the wrong site-packages directory.
It is also easy to forget python3.7-distutils or python3.7-venv, which can make bootstrapping or environment setup more frustrating than it needs to be.
Summary
- Check
python3.7 --versionfirst so you know the interpreter exists. - Install
python3.7,python3.7-venv, andpython3.7-distutilsif needed. - Bootstrap pip with
python3.7 get-pip.py. - Prefer
python3.7 -m pip ...over barepipcommands. - Use a virtual environment when the packages are for a project rather than the whole machine.
Related reading
- How can I iterate over overlapping current, next pairs of values from a list?
- How can I iterate over rows in a Pandas DataFrame?
- How can I list or discover queues on a RabbitMQ exchange using python?
- How can I list the contents of a directory in Python?
- How can I make a Python script standalone executable to run without any dependency?
- How can I make a Python script standalone executable to run without any dependency?
- How can I make one python file run another?
- How can I map True/False to 1/0 in a Pandas DataFrame?
.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.