• Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Install Python 3.7 on Ubuntu, Debian and LinuxMint

Written by Rahul, Updated on August 21, 2020

At the writing time of this article Python 3.7.9 latest stable version of 3.7 series is available to install. This article will help you to install Python 3.7.9 on Ubuntu and LinuxMint operating system. You can visit here to read more about Python releases.

Prerequisites

It is an good practice to keep packages up to date. So, first of all upgrade current packages on your system by running following commands.

sudo apt update && sudo apt upgrade

Then, Use the following command to install prerequisites for Python before installing it.

sudo apt-get install wget build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev \
    libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev

Step 1 – Download Python 3.7

Download Python using following command from python official site. You can also download latest version in place of specified below.

cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz

After finishing the downloading, extract the archive file.

sudo tar xzf Python-3.7.9.tgz

Step 2 – Install Python 3.7

Use below set of commands to compile Python source code on your system using altinstall.

cd Python-3.7.9
sudo ./configure --enable-optimizations
sudo make altinstall

make altinstall is used to prevent replacing the default python binary file /usr/bin/python.

Step 3 – Check Python Version

Check the latest version installed of python using below command

python3.7 -V

Python-3.7.9

Conclusion

This tutorial helps you to install Python 3.7 on your Ubuntu, Debian and Linuxmint systems.

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

126 Comments

  1. Avatar davidm Reply
    January 2, 2021 at 6:11 pm

    I have a 16.04 version of Ubuntu which comes with python 3.5. I am not a python guy at all but I need python 3.7 to run an application. I would like to replace 3.5 with 3.7 in /usr/bin. The instructions on this page for downloading and creating python 3.7 seemed to work perfectly (thanks so much for that). However, I need 3.7 to be my default python3 version. I tried using ‘make install’ instead of ‘make altinstall’ to no effect. How do I do this?
    Regards.

    • Avatar Naveen Vasudevan Reply
      February 27, 2021 at 1:47 am

      sudo update-alternatives –config python3 run this command and then select your required version from the list

  2. Avatar tyson Reply
    December 8, 2020 at 6:20 am

    great easy to follow instructions

  3. Avatar PosReady Reply
    November 23, 2020 at 6:56 pm

    Hey, i installed Python 3.7.8 on Manjaro (Arch) and instruction for installing/compiling Python 3.7.x:

    please install gcc before download python.

    (sudo pacman -S gcc)

    okay. Next install make:
    (sudo pacman -S make)

    and going to download the python on instruction and compiling.

    Good Luck

  4. Avatar Espresso Man Reply
    November 6, 2020 at 1:33 pm

    Thanks for posting that info and updating it Rahul. Well done.

  5. Avatar Gunter Reply
    August 5, 2020 at 7:25 am

    Hi Rahul,

    very useful tutorial, I used it to install Python 3.7 on my ARM64 Odroid C4 running Ubuntu 20.04 – and it worked!

    Thanks mate!

  6. Avatar Jan Reply
    July 6, 2020 at 4:11 pm

    Hi Rahul,

    this is very helpful! thanks a lot.

    One small input: on my system, I didnt have wget installed. Maybe adding the command sudo apt install wget would make this post even better.

    Cheers,
    Jan

    • Rahul Rahul Reply
      July 8, 2020 at 7:08 am

      Thanks Jan, Added command to install wget.

  7. Avatar Peter Reply
    July 4, 2020 at 6:31 pm

    A big “Thank you!” Rahul for your very clean and complete description that has reliably installed Python 3.7 on my Ubuntu 18.10.

  8. Avatar Danilo Dara Reply
    May 28, 2020 at 5:30 pm

    3.7.7 onboard and running.
    Thank you so much.

  9. Avatar ADG Reply
    May 7, 2020 at 11:26 pm

    so helpfull

  10. Avatar Sunnchilde Reply
    November 12, 2019 at 8:23 pm

    Thank you so much! That worked great.

  11. Avatar No Reply
    October 28, 2019 at 1:52 pm

    Installing works fine, but what if I want to unistall it (altinstall)? make unistall does not work 🙁

  12. Avatar Maria Carmela Raguso Reply
    October 17, 2019 at 7:36 pm

    I guys, thank u for this tutorial.
    i’m new user of Python.
    Need to install Python 3.7 on Ubuntu, which version of the OS would you racommend?

    thank for you help

  13. Avatar Konrad Reply
    October 16, 2019 at 7:00 am

    where exacly I can find the python3.7.4 interpreter

  14. Avatar mild Reply
    October 13, 2019 at 5:56 am

    very helpful!

  15. Avatar Rajarajan Reply
    October 8, 2019 at 8:14 pm

    Hi All,

    I m getting the below error while trying to compile python 3.7.4 . I m using openssl version OpenSSL 1.0.2o.

    My config command : ./configure –enable-optimizations –with-ensurepip=install –with-openssl=/usr/local/openssl/

    *** WARNING: renaming “_ssl” since importing it failed: libssl.so.1.0.0: cannot open shared object file: No such file or directory
    *** WARNING: renaming “_hashlib” since importing it failed: libssl.so.1.0.0: cannot open shared object file: No such file or directory

    Python build finished successfully!
    The necessary bits to build these optional modules were not found:
    _lzma _tkinter _uuid
    readline
    To find the necessary bits, look in setup.py in detect_modules() for the module’s name.

    The following modules found by detect_modules() in setup.py, have been
    built by the Makefile instead, as configured by the Setup files:
    _abc atexit pwd
    time

    Following modules built successfully but were removed because they could not be imported:
    _hashlib _ssl

    Could not build the ssl module!
    Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
    LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381

    • Avatar Florent Forest Reply
      October 15, 2019 at 9:58 am

      I had the same issue. Solved it by installing the SSL development package (libssl-dev on Mint, probably same on Debian/Ubuntu). Take a look at this SO answer: https://stackoverflow.com/a/44758621/9698048

    • Avatar Pavol Reply
      January 21, 2020 at 12:09 pm

      Hi RAJARAJAN,
      the problem here is, that openssl must be compiled with CFLAGS=-fPIC, otherwise python won’t compile it.

      Details: https://stackoverflow.com/questions/28234300/usr-local-ssl-lib-libcrypto-a-could-not-read-symbols-bad-value

      Pavol

  16. Avatar Md. Mazharula Alam Sanvi Reply
    October 3, 2019 at 4:21 pm

    It was very helpful.

  17. Avatar tony.carman Reply
    September 20, 2019 at 2:50 am

    Good doc. Appears to be a clean install first round through. Thank you for the nice work.

  18. Avatar SLBasu Reply
    September 18, 2019 at 4:48 pm

    Hi,
    Thanks a lot. I am new to Ubuntu and I did not know that Python 3.6 was already installed in my system. So, can you tell how to uninstall Python 3.7.4? I don’t want to keep too many instances of Python. I am using Ubuntu 18.04.

  19. Avatar Nadine Reply
    September 16, 2019 at 6:55 pm

    I have successfully downloaded Python 3.7.4 but I am unable to find a way to run the program using Linux Mint.

  20. Avatar Malcolm Reply
    September 13, 2019 at 11:46 pm

    Your instructions were complete
    It just worked! To Be Honest I am surprised because most Linux stuff doesn’t work quite as advertised.

    Thank you

  21. Avatar Cormac McClean Reply
    September 13, 2019 at 4:20 pm

    Thanks very much. Working on Ubuntu 16.04 which has Python 3.5 and needed to have 3.7. Very clear instructions.

  22. Avatar DADA_CHRIS Reply
    September 12, 2019 at 5:39 am

    ModuleNotFoundError: No module named ‘_ctypes’
    make: *** [altinstall] Error 1

    • Avatar miker Reply
      October 8, 2019 at 1:50 am

      if running on ubuntu 18, mint 19, install dependencies

      sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev openssl libgdbm-dev libgdbm-compat-dev liblzma-dev libreadline-dev libncursesw5-dev libffi-dev uuid-dev

  23. Avatar Sidney Farias da silva Reply
    September 8, 2019 at 2:55 pm

    Thank you so much, perfect congratulations

  24. Avatar Ed Reply
    September 7, 2019 at 8:42 pm

    Worked perfectly for me on the first try! Thank you very much!

  25. Avatar Srujan Reply
    September 5, 2019 at 8:58 am

    Works perfectly. Thank you so much 😀

  26. Avatar Alex Reply
    September 1, 2019 at 11:08 pm

    I am sorry this method is not working for me; running Linux Mint
    last version. Python 3.4.7 getting the following message:

    zipimport.ZipImportError: can’t decompress data; zlib not available
    Makefile:1142: recipe for target ‘altinstall’ failed
    make: *** [altinstall] Error 1

  27. Avatar ian Reply
    August 31, 2019 at 1:19 am

    Many thanks for the Python 3.7.4 install instructions.

  28. Avatar jacks neto Reply
    August 30, 2019 at 10:14 am

    I been trying to find the solution for almost a week had so much trouble, but following your tutorial was a success. keep up the good work.

  29. Avatar mike lancaster Reply
    August 29, 2019 at 2:25 pm

    Very informative and helped a lot!

  30. Avatar Jura Reply
    August 27, 2019 at 9:48 am

    Very informative and helped a lot!

  31. Avatar Matheus Reply
    August 22, 2019 at 9:56 pm

    Obrigado! Você me ajudou muito.

  32. Avatar SeongYoonHuh Reply
    August 22, 2019 at 3:48 am

    Thankyou for your idea, I really helpful this post.

    Have a nice day!

  33. Avatar Rajesh Chaudhary Reply
    August 15, 2019 at 3:22 am

    Thanks you. By the way please use pagination or loader for comments. Thanks.

    • Rahul Rahul Reply
      August 15, 2019 at 6:10 am

      Thanks, Rajesh for your suggestion.

  34. Avatar Chibuike Reply
    August 10, 2019 at 6:47 pm

    Thanks so much bro. had much difficulties trying to install python but following your steps have eased my stress.

  35. Avatar abdul Reply
    July 22, 2019 at 12:00 pm

    thank you so much. I’m able to install it on my ec2 instance and get pip3.7 also

  36. Avatar Connor Reply
    July 20, 2019 at 12:50 pm

    This was really useful, thank you!

  37. Avatar Ashlon Reply
    July 6, 2019 at 1:20 pm

    I just bought a System76 laptop, running PopOS on it. These steps worked fine on it. Thanks!

  38. Avatar Gangster Reply
    July 6, 2019 at 6:08 am

    I insatlled it but can anyone tell me how to start it??

    • Avatar SweLG Reply
      July 10, 2019 at 9:37 pm

      type ‘python’ in terminal
      or, if you have written a python script write ‘python3.7 scriptname.py’ in terminal

  39. Avatar Mohee Jarada Reply
    July 5, 2019 at 10:26 am

    You are amazing. I did your steps into different Linux distributions of Ubuntu (Linux Mint 18 + Linux Mint 19 + OpenSuse and ElementaryOS) based and worked smoothly. Much appreciated for this excellent post.

  40. Avatar Adibikar Reply
    June 20, 2019 at 8:31 am

    Hi, i have follow and successfully install python3.7. How do I remove them? Since in “dpkg -l | grep”, python3.7 is not there.

  41. Avatar Donald L Wilson Reply
    June 19, 2019 at 9:21 am

    Anybody happen to know of a shell script that you could run that would tell you which of your files already installed depend on the earlier version of python. That way you could see just how many of your programs needed to be patched?

  42. Avatar Vigi Reply
    June 6, 2019 at 9:00 am

    Linux mint 19 all worked. thank

  43. Avatar Christian Walter Reply
    May 31, 2019 at 8:48 am

    The procedure worked for me, Ubuntu 15.04.
    There were some error notifications upon the command
    sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev \
    libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
    yet the rest of the procedure worked out well.
    The compilation was successful and I can use python3.7 alright so far.
    Thank you for your instruction, cheers!

  44. Avatar shuster oded Reply
    May 30, 2019 at 6:19 am

    very good article Thank you.

  45. Avatar Benjamin Reply
    May 29, 2019 at 5:27 pm

    Thank you! This worked great for me.

  46. Avatar Amey Reply
    May 29, 2019 at 3:31 pm

    Thanks, man. It worked like a charm!

  47. Avatar pee4kotoo Reply
    May 26, 2019 at 8:44 pm

    thanks it helped me

  48. Avatar Akhil Mathew Reply
    May 15, 2019 at 6:02 pm

    Before installing Python 3.7.3
    just execute this command given below for easy working
    $ sudo apt-get install zlib1g-dev

  49. Avatar Doug Reply
    May 13, 2019 at 11:29 pm

    Great instructions. But, they are being done without consideration for the existing ‘Python 3.6.7’ that presently exists on the ‘Linux Mint 19.1 Tessa’ working as the primary platform? There won’t be confusion in regard to anything to do w/python3 then?

  50. Avatar ori Reply
    May 10, 2019 at 10:24 pm

    thanks

  51. Avatar Hamilo Reply
    May 10, 2019 at 10:10 am

    Please help!

    (python-may2019) [email protected]:~/programowanie$ pip install jupyter
    pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
    Collecting jupyter
    Cache entry deserialization failed, entry ignored
    Could not fetch URL https://pypi.python.org/simple/jupyter/: There was a problem confirming the ssl certificate: Can’t connect to HTTPS URL because the SSL module is not available. – skipping
    Could not find a version that satisfies the requirement jupyter (from versions: )
    No matching distribution found for jupyter

    • Avatar Kamrul Reply
      July 25, 2019 at 1:28 pm

      Same here.

  52. Avatar Diego Graf Reply
    May 9, 2019 at 10:36 pm

    thanks, it worked for me!

  53. Avatar Bhagesh Pant Reply
    May 6, 2019 at 5:59 am

    Hi @Rahul_Kumar,

    Thanks for contributing this great article. The output throws a Build error while compiling python source within ‘$ sudo make altinstall’.

    Just want to fork an edit for a successful installation on Ubuntu (18.04 or other).

    It works neatly if you add another LOC within STEP-1 (Prerequisites) as stated under, rest assured installation will be successful.

    $sudo apt-get install libffi-dev

    *** STEP-1 : Prerequisites ***
    $ sudo apt-get install build-essential checkinstall
    $ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev \
    libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
    $ sudo apt-get install libffi-dev

  54. Avatar Fabiano Duarte Reply
    May 5, 2019 at 4:28 pm

    Oh, thanks! It works in my Linux machine.

  55. Avatar Siva S Reply
    May 4, 2019 at 5:10 am

    sudo apt-get install libffi-dev

  56. Avatar JOHN Reply
    April 16, 2019 at 3:16 pm

    Follow the steps to the T and it works well.

  57. Avatar Afzal S H Reply
    April 4, 2019 at 7:15 am

    I needed to install two additional packages; `zlib1g-dev` and `libffi-dev`

  58. Avatar luiz Reply
    March 29, 2019 at 9:23 pm

    Thank you for helping me a lot ..

  59. Avatar Martin von Slawinski Reply
    March 24, 2019 at 10:19 am

    Great article. Worked neatly. THank you

    Einen Gruß aus Deutschland!!!!! (Germany)

    LG, Martin

  60. Avatar chirag Reply
    March 19, 2019 at 7:10 am

    I have this error when i use python3.7 for create virtual enviorment.

    GNU nano 2.9.3 /var/log/apache2/rpg-tukunang-siteminder.log

    [Tue Mar 19 06:56:20.910728 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/var/www/sm/python/lib/python3.7/site-packages/django/db/models/aggregates.py”, line 5, in
    [Tue Mar 19 06:56:20.910731 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] from django.db.models.expressions import Case, Func, Star, When
    [Tue Mar 19 06:56:20.910737 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/var/www/sm/python/lib/python3.7/site-packages/django/db/models/expressions.py”, line 7, in
    [Tue Mar 19 06:56:20.910740 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] from django.db.models import fields
    [Tue Mar 19 06:56:20.910749 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/var/www/sm/python/lib/python3.7/site-packages/django/db/models/fields/__init__.py”, line 11, in
    [Tue Mar 19 06:56:20.910752 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] from django import forms
    [Tue Mar 19 06:56:20.910757 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/var/www/sm/python/lib/python3.7/site-packages/django/forms/__init__.py”, line 6, in
    [Tue Mar 19 06:56:20.910761 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] from django.forms.boundfield import * # NOQA
    [Tue Mar 19 06:56:20.910766 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/var/www/sm/python/lib/python3.7/site-packages/django/forms/boundfield.py”, line 4, in
    [Tue Mar 19 06:56:20.910769 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] from django.forms.widgets import Textarea, TextInput
    [Tue Mar 19 06:56:20.910775 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/var/www/sm/python/lib/python3.7/site-packages/django/forms/widgets.py”, line 21, in
    [Tue Mar 19 06:56:20.910778 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] from .renderers import get_default_renderer
    [Tue Mar 19 06:56:20.910783 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/var/www/sm/python/lib/python3.7/site-packages/django/forms/renderers.py”, line 11, in
    [Tue Mar 19 06:56:20.910786 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] from django.template.backends.jinja2 import Jinja2
    [Tue Mar 19 06:56:20.910792 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/var/www/sm/python/lib/python3.7/site-packages/django/template/backends/jinja2.py”, line 1, in
    [Tue Mar 19 06:56:20.910795 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] import jinja2
    [Tue Mar 19 06:56:20.910800 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/var/www/sm/python/lib/python3.7/site-packages/jinja2/__init__.py”, line 82, in
    [Tue Mar 19 06:56:20.910804 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] _patch_async()
    [Tue Mar 19 06:56:20.910809 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/var/www/sm/python/lib/python3.7/site-packages/jinja2/__init__.py”, line 78, in _patch_async
    [Tue Mar 19 06:56:20.910812 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] from jinja2.asyncsupport import patch_all
    [Tue Mar 19 06:56:20.910818 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/var/www/sm/python/lib/python3.7/site-packages/jinja2/asyncsupport.py”, line 13, in
    [Tue Mar 19 06:56:20.910821 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] import asyncio
    [Tue Mar 19 06:56:20.910826 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/usr/lib/python3.6/asyncio/__init__.py”, line 21, in
    [Tue Mar 19 06:56:20.910830 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] from .base_events import *
    [Tue Mar 19 06:56:20.910835 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/usr/lib/python3.6/asyncio/base_events.py”, line 17, in
    [Tue Mar 19 06:56:20.910838 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] import concurrent.futures
    [Tue Mar 19 06:56:20.910843 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/var/www/sm/python/lib/python3.7/site-packages/concurrent/futures/__init__.py”, line 8, in
    [Tue Mar 19 06:56:20.910849 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] from concurrent.futures._base import (FIRST_COMPLETED,
    [Tue Mar 19 06:56:20.910863 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] File “/var/www/sm/python/lib/python3.7/site-packages/concurrent/futures/_base.py”, line 381
    [Tue Mar 19 06:56:20.910871 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] raise exception_type, self._exception, self._traceback
    [Tue Mar 19 06:56:20.910889 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] ^
    [Tue Mar 19 06:56:20.910897 2019] [wsgi:error] [pid 29306:tid 139714993866496] [remote 188.114.102.126:28470] SyntaxError: invalid syntax

  61. Avatar Lu Reply
    March 4, 2019 at 3:09 am

    Hey, How do you reverse/delete the entire install?

  62. Avatar Peter Sanza Reply
    March 3, 2019 at 2:45 pm

    Two comments:

    1) I find it bad form to build as root. If the build fails (as it did for me) you have a mess to clean up with files/folders owned by root. The Makefile is designed (and intended) to build and test python as an unprivileged user in an unprivileged folder. Only the final step (make altinstall) needs to run as super user.

    2) You might have missed a dependency. My build failed on _ctype module. Although this is listed as an optional module and the build process continues after acknowledging the failure, the build ultimately fails during final installation while pre-compiling the python library. So the python library only gets partially installed and leaves quite the mess to clean up. So maybe it is not so optional? Add “libffi-dev” to the list of libraries to install prior to building. Once I added it, the install went smoothly.

  63. Avatar Manuel Reply
    March 1, 2019 at 4:02 pm

    Great article. Worked neatly. THank you

  64. Avatar sthon Reply
    February 26, 2019 at 9:19 pm

    gracias parce, me fue de mucha utilidad… lastima no tener pa invitarlo a una cerveza…

  65. Avatar Basak Reply
    February 26, 2019 at 2:46 pm

    I need to run Selenium using Python 3.7 on Ubuntu 18.04. Since with above steps Python 3.7 libs gets installed in /usr/local/bin not in /usr/bin, on installation of selenium , selenium binaries compatible with Python 2.7 libs gets installed on running below command:

    sudo pip install selenium .

    Isn’t it be a better idea to install Python3.7 as proper install in /usr/bin instead of alternate install like above?

    • Avatar Peter Sanza Reply
      March 3, 2019 at 2:50 pm

      “make altinstall” intentionally installs in the alternate directory to preserve your distribution’s default python in the “normal” place. If you use “make install” instead, this will install the new python in the normal place replacing the default one that came with your distribution. HOWEVER, it is VERY LIKELY you will break several things in your distribution that depend on the version of python that came with your distribution. Use at your own risk.

      • Avatar davidm Reply
        January 2, 2021 at 6:18 pm

        I posted a comment before I saw this reply:
        I have a 16.04 version of Ubuntu which comes with python 3.5. I am not a python guy at all but I need python 3.7 to run an application. I would like to replace 3.5 with 3.7 in /usr/bin. The instructions on this page for downloading and creating python 3.7 seemed to work perfectly (thanks so much for that). However, I need 3.7 to be my default python3 version. I tried using ‘make install’ instead of ‘make altinstall’ to no effect. How do I do this?
        Regards.

  66. Avatar aldrin monteiro Reply
    February 26, 2019 at 2:16 pm

    Very good. You save me

  67. Avatar Andreas Reply
    February 21, 2019 at 1:08 pm

    I follow all the instructions as given but I get this error when I do
    sudo make altinstal

    from _ctypes import Union, Structure, Array
    ModuleNotFoundError: No module named ‘_ctypes’
    Makefile:1140: recipe for target ‘altinstall’ failed
    make: *** [altinstall] Error 1

    • Avatar Peter Sanza Reply
      March 3, 2019 at 2:51 pm

      See my post how to solve this.

  68. Avatar Rob Reply
    February 11, 2019 at 6:45 pm

    Worked like a charm except i had to run `$ apt-get install libffi-dev` due to the build failing…may want to add to your notes. Thanks.

  69. Avatar Robert Reply
    February 9, 2019 at 4:56 pm

    When I try to build with pip I get this error.

    ./configure –enable-optimizations –with-ensurepip=install
    sudo make altinstall

    What does it mean?

    Exception:
    Traceback (most recent call last):
    File “/tmp/tmp24wspe96/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/base_command.py”, line 143, in main
    status = self.run(options, args)
    File “/tmp/tmp24wspe96/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/install.py”, line 259, in run
    with self._build_session(options) as session:
    File “/tmp/tmp24wspe96/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/base_command.py”, line 79, in _build_session
    insecure_hosts=options.trusted_hosts,
    File “/tmp/tmp24wspe96/pip-18.1-py2.py3-none-any.whl/pip/_internal/download.py”, line 337, in __init__
    self.headers[“User-Agent”] = user_agent()
    File “/tmp/tmp24wspe96/pip-18.1-py2.py3-none-any.whl/pip/_internal/download.py”, line 100, in user_agent
    zip([“name”, “version”, “id”], distro.linux_distribution()),
    File “/tmp/tmp24wspe96/pip-18.1-py2.py3-none-any.whl/pip/_vendor/distro.py”, line 120, in linux_distribution
    return _distro.linux_distribution(full_distribution_name)
    File “/tmp/tmp24wspe96/pip-18.1-py2.py3-none-any.whl/pip/_vendor/distro.py”, line 675, in linux_distribution
    self.version(),
    File “/tmp/tmp24wspe96/pip-18.1-py2.py3-none-any.whl/pip/_vendor/distro.py”, line 735, in version
    self.lsb_release_attr(‘release’),
    File “/tmp/tmp24wspe96/pip-18.1-py2.py3-none-any.whl/pip/_vendor/distro.py”, line 892, in lsb_release_attr
    return self._lsb_release_info.get(attribute, ”)
    File “/tmp/tmp24wspe96/pip-18.1-py2.py3-none-any.whl/pip/_vendor/distro.py”, line 550, in __get__
    ret = obj.__dict__[self._fname] = self._f(obj)
    File “/tmp/tmp24wspe96/pip-18.1-py2.py3-none-any.whl/pip/_vendor/distro.py”, line 998, in _lsb_release_info
    stdout = subprocess.check_output(cmd, stderr=devnull)
    File “/home/robert/src/Python-3.7.2/Lib/subprocess.py”, line 395, in check_output
    **kwargs).stdout
    File “/home/robert/src/Python-3.7.2/Lib/subprocess.py”, line 487, in run
    output=stdout, stderr=stderr)
    subprocess.CalledProcessError: Command ‘(‘lsb_release’, ‘-a’)’ returned non-zero exit status 1.
    Makefile:1140: recipe for target ‘altinstall’ failed
    make: *** [altinstall] Error 2

  70. Avatar HubertHarbus Reply
    February 9, 2019 at 12:16 am

    I’m doing all that and in the end I’m still getting:

    [email protected]:/usr/src/Python-3.7.2 $ python3 –version
    Python 3.5.3

    It seems 3.7.2 didn’t get installed correctly??

    • Avatar Yash Reply
      February 12, 2019 at 4:49 pm

      try this,
      $ python3.7 –version

  71. Avatar sam Reply
    February 1, 2019 at 5:40 am

    works beautifully on Mint 19.1

  72. Avatar Mike Reply
    January 31, 2019 at 2:24 am

    Big thankyou!

  73. Avatar Oseias D. Farias Reply
    January 12, 2019 at 5:47 pm

    Thank You!

  74. Avatar Alex Reply
    December 17, 2018 at 4:53 am

    Hi Rahul, this is what i get when i type “cd Python3.7.1”:

    bash: cd: Python3.7.1: No such file or directory

    • Avatar Alex Reply
      December 20, 2018 at 9:28 pm

      Never mind, fixed it.

  75. Avatar daniele Reply
    December 13, 2018 at 8:49 am

    Hi Rahul, many thanks for your support,.
    I successfully installed Python 3.7.1 , but it works just on the terminal.
    Because I’m beginner I wish to use an easier interface: How can I install an IDE on my desktop?
    many Thanks.
    BR
    Daniele

    • Rahul Rahul Reply
      December 13, 2018 at 9:51 am

      You can use Visual Studio Code IDE

      • Avatar Kyle Reply
        January 5, 2019 at 12:35 am

        Also, check out this for using python with vscode:
        https://code.visualstudio.com/docs/languages/python

  76. Avatar bnvmn Reply
    December 9, 2018 at 6:46 pm

    Stuped article. Now i not use python…. samples crashed!!!

  77. Avatar Rahul V Reply
    December 7, 2018 at 12:42 pm

    Hi ,

    When I follow the instruction , python3.7 is getting installed in usr/local/bin and not in usr/bin where other python versions are installed .
    Thus I have two questions

    1) Is it supposed to be installed at usr/bin or usr/local/bin ?
    2)when I use the command :
    ***
    virtualenv -p /usr/local/bin/python3.7 py37_test1
    ****
    to create a virtual env using python 3.7 , i get the following error :
    *****************
    Running virtualenv with interpreter /usr/local/bin/python3.7
    Using base prefix ‘/usr/local’
    New python executable in /home/rahul/py37_test1/bin/python3.7
    Also creating executable in /home/rahul/py37_test1/bin/python
    Installing setuptools, pip, wheel…

    Complete output from command /home/rahul/py37_test1/bin/python3.7 – setuptools pip wheel:
    Traceback (most recent call last):
    File “”, line 8, in
    File “/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/__init__.py”, line 40, in
    File “/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py”, line 8, in
    File “/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py”, line 12, in
    File “/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/__init__.py”, line 6, in
    File “/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/completion.py”, line 6, in
    File “/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/base_command.py”, line 18, in
    File “/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/download.py”, line 38, in
    File “/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/utils/glibc.py”, line 3, in
    File “/usr/local/lib/python3.7/ctypes/__init__.py”, line 7, in
    from _ctypes import Union, Structure, Array
    ModuleNotFoundError: No module named ‘_ctypes’

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File “”, line 11, in
    ImportError: cannot import name ‘main’ from ‘pip’ (/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/__init__.py)
    —————————————-
    …Installing setuptools, pip, wheel…done.
    Traceback (most recent call last):
    File “/usr/local/lib/python2.7/dist-packages/virtualenv.py”, line 2462, in
    main()
    File “/usr/local/lib/python2.7/dist-packages/virtualenv.py”, line 762, in main
    symlink=options.symlink,
    File “/usr/local/lib/python2.7/dist-packages/virtualenv.py”, line 1015, in create_environment
    install_wheel(to_install, py_executable, search_dirs, download=download)
    File “/usr/local/lib/python2.7/dist-packages/virtualenv.py”, line 968, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
    File “/usr/local/lib/python2.7/dist-packages/virtualenv.py”, line 854, in call_subprocess
    raise OSError(“Command {} failed with error code {}”.format(cmd_desc, proc.returncode))
    OSError: Command /home/rahul/py37_test1/bin/python3.7 – setuptools pip wheel failed with error code 1

    **********

    How can I create a virtual env using python3.7

    • Avatar José Luís Silva Reply
      January 31, 2019 at 2:25 pm

      Hi,
      Same problem here, if someone knows how to fix this, it would be very helpful

      • Avatar Ricardo Reply
        February 12, 2019 at 9:41 am

        sudo apt-get install libffi-dev (on Debian)

        Segura no puta merda e vai com fé, jovem padawan! haha

        • Avatar Ankush Reply
          February 18, 2019 at 10:45 am

          Hi,
          I want to know the same command for ubuntu

  78. Avatar Someguy Reply
    November 26, 2018 at 3:55 pm

    Thanks for this. I had to ‘sudo apt-get install libffi-dev’ as well to make the install complete without errors, missed ctypes module otherwise.

    • Avatar Fabio Reply
      December 7, 2018 at 12:04 am

      Many thanks mate!

  79. Avatar Don Reply
    October 17, 2018 at 3:25 pm

    When I enter: wget wget https://www.python …… etc I get message:
    permission denied
    and
    cannot write to python-3.7.0.tgz(success).

    • Avatar Darren Haynes Reply
      October 22, 2018 at 7:52 pm

      Its a typo. The line should start with “sudo wget”, not “wget wget”.

      • Rahul Rahul K. Reply
        October 23, 2018 at 3:35 am

        Thanks, Darren

        I have corrected the typo.

  80. Avatar gatopeich Reply
    October 11, 2018 at 9:08 am

    You should not use “sudo” except perhaps for the final installation command.

  81. Avatar Orr Reply
    September 19, 2018 at 1:27 pm

    Awesome instructions, straight and to the point. I would only add for beginners ‘you need to be a bit patient while doing ‘sudo make altinstall’.`

  82. Avatar nikolay Reply
    September 2, 2018 at 1:41 am

    Python 2.7.15rc1
    and i get this when I run python -V or python –version

    • Avatar Alex Reply
      December 17, 2018 at 4:51 am

      try using python3 -V

  83. Avatar nikolay Reply
    September 2, 2018 at 1:38 am

    The directory ‘/home/nikolay/.cache/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
    The directory ‘/home/nikolay/.cache/pip’ or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.

    what does this means?

  84. Avatar jacobo Reply
    August 24, 2018 at 3:33 pm

    muchas gracias instalación satisfactoria en instancia de google cloud debían 9 muy buen tutorial

  85. Avatar Douglas Reply
    August 14, 2018 at 4:03 am

    Didn’t work here…
    The following error appears at the end of the ‘sudo make altinstall’:

    ModuleNotFoundError: No module named ‘_ctypes’
    Makefile:1132: recipe for target ‘altinstall’ failed
    make: *** [altinstall] Error 1

    • Avatar Antoni M Reply
      August 19, 2018 at 4:57 pm

      I had the same error. Works with:

      sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev openssl libgdbm-dev libgdbm-compat-dev liblzma-dev libreadline-dev libncursesw5-dev libffi-dev uuid-dev

      or

      sudo apt-get install libffi-dev

      https://bugs.python.org/issue31652

  86. Avatar Maurizio Reply
    August 12, 2018 at 10:33 am

    Thank you very much. i installed python3.7 in mint 19 Tara successfully

  87. Avatar Namiam Reply
    January 16, 2018 at 4:00 pm

    I installed successfully on Linux Mint 18.3
    Thanks and highly appreciate.

  88. Avatar unkb Reply
    May 24, 2017 at 10:41 pm

    HTTP request sent, awaiting response… 200 OK
    Length: 19611207 (19M) [application/octet-stream]
    Python-3.4.5.tgz: Permission denied

    Cannot write to ‘Python-3.4.5.tgz’ (Success).

    help?

    • Rahul Rahul K. Reply
      May 26, 2017 at 4:01 am

      HI UNKB,

      It looks you have the issue with write on your system. Try to download the file in some other directory like /tmp

    • Avatar edgar Reply
      October 26, 2017 at 6:48 pm

      try adding “sudo” at the beggining. it work for me.

      • Avatar anil Reply
        November 30, 2017 at 10:41 pm

        thanks it worked for me too

  89. Avatar Gaurav S Reply
    December 6, 2016 at 2:47 pm

    Hey,

    The tutorial is easy enough to follow, and I went till the following command:
    sudo make altinstall
    But it goes into an infinite loop, and it never ends.
    Actually the following line keep appearing after 2-3 min :
    /bin/sh ./configure
    PS: I’m trying to install it in Debian(wheezy) in beaglebone black.

    Thanks

  90. Avatar xhoi Reply
    May 2, 2016 at 5:10 pm

    I can’t check the python version

    • Avatar Suraj Tripathi Reply
      July 19, 2016 at 12:59 pm

      use this:
      python -V

  91. Avatar Dan Reply
    April 12, 2016 at 2:42 am

    Thanks Rahul,

    Very easy to follow instructions. Note to self: if at first it doesn’t work, sudo it and try again 🙂

    Thanks again.

    • Avatar DIMASPUTRA Reply
      June 14, 2016 at 12:15 pm

      [email protected]:/usr/src$ sudo tar xzf Python-3.4.4.tgz
      tar (child): Python-3.4.4.tgz: Cannot open: No such file or directory
      tar (child): Error is not recoverable: exiting now
      tar: Child returned status 2
      tar: Error is not recoverable: exiting now

      • Avatar niunj Reply
        September 4, 2018 at 12:31 am

        nigger

        • Avatar Kom Reply
          July 31, 2019 at 8:17 am

          I am new to Linux..I followed every single step of yours, but now iam not getting the command to open my python as a usr…

  92. Avatar Mirek Reply
    March 11, 2016 at 1:45 am

    Grate example how to install python. One small detail…. you can’t highlight the text in black windows and copy in to terminal. Every thing need to be retyped.
    Can you review that article and just place the comments as regular text?

    Regards.

  93. Avatar Dan Reply
    February 24, 2016 at 1:24 am

    Thanks for the well explained instructions. I only had trouble extracting the tar but added sudo and everything worked as it should.

    Thanks again

  94. Avatar G.G. Reply
    January 28, 2016 at 7:47 pm

    Hi Rahul:

    Thank you for your easy to follow tutorial. I get this response:

    The directory ‘/home/xxxxx/.cache/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.

    The directory ‘/home/xxxxx/.cache/pip’ or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.

    after entering: sudo make altinstall

    I’m a newbie to Linux (Lubuntu) and Python. Please help. Thank you.

    BTW, the OS came with python 2.7.6 installed. Can/do I remove it, if so how?

  95. Avatar Phillip Reply
    November 20, 2015 at 4:32 pm

    Does replacing Python 2.7 with Python 3.X in /usr/bin/python affect my system in anyway negatively

    • Avatar Teo Reply
      March 20, 2019 at 5:55 pm

      YES, it will break your system.

Leave a Reply Cancel reply

Popular Posts

  • How To Install Python 3.9 on Debian 10
  • Download Ubuntu 20.04 LTS – DVD ISO Images
  • Linux Run Commands As Another User
  • How to Check PHP Version (Apache/Nginx/CLI)
  • How To Install and Configure GitLab on Ubuntu 20.04
  • How to Install PyCharm on Ubuntu 20.04
  • How to Check Ubuntu Version with Command or Script
  • How to Set all directories to 755 And all files to 644
© 2013-2021 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy