How to Install Python 3.7.2 in Ubuntu 18.04 / 18.10

February 22, 2019 — 9 Comments

This quick tutorial is for those who want to install the latest Python 3.7.2 in Ubuntu 18.04 LTS, Linux Mint 19.x, and Ubuntu 18.10.

Ubuntu 18.04 comes with Python 2.7 and Python 3.6 out-of-the-box, and later includes Python 3.7.1 in its updates (universe) repository.

For the updated Python 3.7.2, you can do following steps to use the ToolChain PPA packages.

1. Open terminal either via Ctrl+Alt+T keyboard shortcut or by searching for “Terminal” from app launcher. When it opens, run command to add the ToolChain PPA:

sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa

Type user password (no visual feedback) when it asks and hit Enter to continue.

2. Then run command to install Python3.7:

sudo apt install python3.7

For Linux Mint 19.x, run command sudo apt update to check updates first.

3. As the PPA contains other updates toolchain packages, e.g., gcc-7.4.0, gcc-8.2.0, and python-3.6.8, you may remove the PPA afterwards via Software & Updates -> Other Software tab.

4. To make python3 use the new installed python 3.7.2 instead of the default 3.6.7, run commands to add python3.7 as choice:

This step may cause issues that depends python3.6! As I know, terminal won’t launch afterwards unless you recreate a symlink to python3.6
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2

Then switch between the two versions via command:

sudo update-alternatives --config python3

That’s it. Enjoy!

I'm a freelance blogger who started using Ubuntu 5+ years ago and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me on Google Plus or email to ubuntuhandbook1@gmail.com

9 responses to How to Install Python 3.7.2 in Ubuntu 18.04 / 18.10

  1. Hi and thank you for the walkthrough!
    As announced, the terminal doesn’t open anymore; how do I recreate a symlink to python3.6 (or otherwise make the terminal open again?

    Thanks in advance.

    • For Ubuntu 18.04, open terminal and run following 2 commands:

      sudo rm /usr/bin/python3
      
      sudo ln -s python3.6 /usr/bin/python3
      • is there a way that i don’t have to run these lines for and keep the terminal containing them open every time?

  2. I have the same problem, the gnome terminal could not be opened more. This made missed module named apt_pkg. I end up installed ubuntu again.

  3. root@ubuntu:~# apt-get install python3.7
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package python3.7

  4. i fix it download synaptic packege maneger and seargh for python 3.7 find it green colour becouse installed earler click on it and chose mark for remove . same thinge find python 3.6 and mark for reinstallation ….enjoy/home/mo1/Pictures/Screenshot from 2019-08-15 04-10-13.png

  5. Hi, python 3.7 runs fine. However I cannot create new virtual env using python3 -m venv .env command. It says install python3-venv package, but I already have this package with version 3.6.7. How can I install this package with 3.7 version?

  6. Oh nice! after do this I can’t run apt-get update.

    It returns whole lot bunch of errors.

    “`
    Traceback (most recent call last):
    File “/usr/lib/cnf-update-db”, line 8, in
    from CommandNotFound.db.creator import DbCreator
    File “/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py”, line 11, in
    import apt_pkg
    ModuleNotFoundError: No module named ‘apt_pkg’
    Error in sys.excepthook:
    Traceback (most recent call last):
    File “/usr/lib/python3/dist-packages/apport_python_hook.py”, line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
    File “/usr/lib/python3/dist-packages/apport/__init__.py”, line 5, in
    from apport.report import Report
    File “/usr/lib/python3/dist-packages/apport/report.py”, line 30, in
    import apport.fileutils
    File “/usr/lib/python3/dist-packages/apport/fileutils.py”, line 23, in
    from apport.packaging_impl import impl as packaging
    File “/usr/lib/python3/dist-packages/apport/packaging_impl.py”, line 24, in
    import apt
    File “/usr/lib/python3/dist-packages/apt/__init__.py”, line 23, in
    import apt_pkg
    ModuleNotFoundError: No module named ‘apt_pkg’

    Original exception was:
    Traceback (most recent call last):
    File “/usr/lib/cnf-update-db”, line 8, in
    from CommandNotFound.db.creator import DbCreator
    File “/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py”, line 11, in
    import apt_pkg
    ModuleNotFoundError: No module named ‘apt_pkg’
    Reading package lists… Done
    E: Problem executing scripts APT::Update::Post-Invoke-Success ‘if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi’
    E: Sub-process returned an error code
    “`

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

*