Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Install pip for python 3.7 on Ubuntu 18?

Tags:

python

pip

ubuntu

People also ask

How do I run Python 3.7 on Ubuntu?

Finally, as the required PPA is added into our Ubuntu 18.04 machine, we can now simply use apt command to install Python 3.7. The -y option in apt informs command to set automatic yes to prompts. Output $ sudo apt install python3. 7 -y Reading package lists...

Does Ubuntu 18.04 come with pip?

Ubuntu 18.04 comes with Python 3 installed by default, but it does not come with pip.


In general, don't do this:

pip install package

because, as you have correctly noticed, it's not clear what Python version you're installing package for.

Instead, if you want to install package for Python 3.7, do this:

python3.7 -m pip install package

Replace package with the name of whatever you're trying to install.

Took me a surprisingly long time to figure it out, too. The docs about it are here.

Your other option is to set up a virtual environment. Once your virtual environment is active, executable names like python and pip will point to the correct ones.


A quick add-on to mpenkov's answer above (didn't want this to get lost in the comments)

For me, I had to install pip for 3.6 first

sudo apt install python3-pip

now you can install python 3.7

sudo apt install python3.7

and then I could install pip for 3.7

python3.7 -m pip install pip

and as a bonus, to install other modules just preface with

python3.7 -m pip install <module>

EDIT 1 (12/2019):

I know this is obvious for most. but if you want python 3.8, just substitute python3.8 in place of python3.7

EDIT 2 (5/2020):

For those that are able to upgrade, Python 3.8 is available out-of-the-box for Ubuntu 20.04 which was released a few weeks ago.


This works for me.

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Then this command with sudo:

python3.7 get-pip.py

Based on this instruction.


I used apt-get to install python3.7 in ubuntu18.04. The installations are as follows.

  1. install python3.7
sudo apt-get install python3.7 
  1. install pip3. It should be noted that this may install pip3 for python3.6.
sudo apt-get install python3-pip 
  1. change the default of python3 for python3.7. This is where the magic is, which will make the pip3 refer to python3.7.
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1

Hope it works for you.