52

I have python3.5 already in linux ubuntu. I have downloaded the python3.7.tar www.python.org.

But i have no idea how to install it. How to upgrade to python 3.7? Thanks.

  • 3
    Shouldn't this question be posted on askubuntu.com ? – Mahir Islam Jul 11 '18 at 08:24
  • 2
    @mahir: … possibly. Even though "Python" falls under SO's missives, the question is not *about* Python. It appears to me OP simply does not know what to do with a tar file, which falls under "general computing". – Jongware Jul 11 '18 at 08:42
  • 1
    See [How do I install the latest Python 2.7.X or 3.X on Ubuntu?](//askubuntu.com/q/101591) over on *Ask Ubuntu*. – Martijn Pieters Feb 16 '19 at 16:25

2 Answers2

63

Try this if you are on ubuntu:

sudo apt-get update
sudo apt-get install build-essential libpq-dev libssl-dev openssl libffi-dev zlib1g-dev
sudo apt-get install python3-pip python3.7-dev
sudo apt-get install python3.7

In case you don't have the repository and so it fires a not-found package you first have to install this:

sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update

more info here: http://devopspy.com/python/install-python-3-6-ubuntu-lts/

Mr.Web
  • 6,992
  • 8
  • 51
  • 86
jc1850
  • 1,101
  • 7
  • 16
  • I don't think that'll work with 3.7 since it's not yet in the main repositories. – Bernhard Jul 11 '18 at 08:35
  • 1
    I tested it and it worked – jc1850 Jul 11 '18 at 08:36
  • 2
    I tested it and it didn't work because it lacked the PPA... – Hadrien TOMA Jul 30 '18 at 09:01
  • does not work on 14.04 for python3.7. there are no packages for trusty. – Christopher Hunter Sep 20 '18 at 21:12
  • Tested on `Ubuntu 16.04.5 LTS`. Not working. Please update answer with PPA instructions. – yclian Sep 23 '18 at 15:35
  • 11
    I just installed python 3.7 in Ubuntu 16.04 using the above instructions and using the Deadsnakes PPA . To add the PPA just execute `sudo add-apt-repository ppa:deadsnakes/ppa` and `sudo apt-get update`. – Diego Rodríguez Sep 28 '18 at 09:45
  • 3
    This worked for me on Ubuntu 18.04! – Dan Nov 30 '18 at 15:43
  • 1
    Confirmed to work on Ubuntu 18.04. No additional PPA required (Jan 2019) – Kalob Taulien Jan 07 '19 at 15:57
  • Confirmed to require ppa on Ubuntu 18.04 – Kwame Jan 18 '19 at 14:07
  • 2
    why`python3-dev` and not `python3.7-dev`? – dangel Apr 27 '19 at 01:35
  • It worked for me (the last step `sudo apt-get install python3.7` did nothing as satisfied already) but just a note: you will still have to update the symbolic links manually if you want 3.7 to be the one that pops up when calling `python` or `python3` – Pynchia May 14 '19 at 13:09
  • 1
    furthermore: in case you cannot create a venv anymore and `sudo apt-get install python3-venv` fails, do `sudo apt-get install python3.7-venv` instead – Pynchia May 14 '19 at 13:46
  • 1
    some caution about making python3.7 the default, I've had some serious issues when doing this later down the road when updating other software. I'm sure I did something wrong, but still – dangel May 15 '19 at 01:00
  • Add python3.7 to update-alternatives ```sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2``` Update python3 to point to python3.7 ```sudo update-alternatives --config python3``` Enter number for python3.7 ```python3 -V``` https://jcutrer.com/linux/upgrade-python37-ubuntu1810 – tnusraddinov Dec 05 '19 at 09:08
  • 1
    Doesn't worksasd – Anthony Aug 15 '21 at 18:41
  • How do you run it? `python --version` still gives me the old version. – Oleg Yablokov Jul 26 '22 at 12:39
23

On ubuntu you can add this PPA Repository and use it to install python 3.7: https://launchpad.net/~jonathonf/+archive/ubuntu/python-3.7

Or a different PPA that provides several Python versions is Deadsnakes: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa

See also here: https://askubuntu.com/questions/865554/how-do-i-install-python-3-6-using-apt-get (I know it says 3.6 in the url, but the deadsnakes ppa also contains 3.7 so you can use it for 3.7 just the same)

If you want "official" you'd have to install it from the sources from the site, get the code (which you already downloaded) and do this:

tar -xf Python-3.7.0.tar.xz
cd Python-3.7.0
./configure
make
sudo make install        <-- sudo is required.

This might take a while

Community
  • 1
  • 1
Bernhard
  • 1,253
  • 8
  • 18
  • Thanks, I have seen this answer in askubuntu. But is there an official way by Python official..? –  Jul 11 '18 at 17:11
  • I'd go with the PPA, but I edited my post for an official way using the code from the site. – Bernhard Jul 12 '18 at 06:27
  • 1
    I tried the official way, until failed in the `make install`.. –  Jul 12 '18 at 08:09
  • I tried this but it also failed when running `make install`. I read the docs and it said that if the system already had Python preinstalled (which mine does as Python 3.6.6) you should run `make altinstall` instead. But I got the exact same error – dabadaba Oct 01 '18 at 19:52
  • I`m sorry, I can`t really help you with ´make install´ problems, I`d suggest using the PPA. – Bernhard Oct 02 '18 at 10:38