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...
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.
sudo apt-get install python3.7
sudo apt-get install python3-pip
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
Hope it works for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With