Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»Python»How To Install Python 3.7 on CentOS/RHEL 7 & Fedora 34/33

    How To Install Python 3.7 on CentOS/RHEL 7 & Fedora 34/33

    RahulBy RahulJuly 1, 20182 Mins ReadUpdated:July 17, 2021

    Python is a powerful programming language. It is very friendly and easy to learn. At the writing time of this article Python 3.7.11 (in Python 3.7 series) latest stable version is available to download and install. This tutorial will help you to install Python 3.7.11 on your CentOS, Red Hat & Fedora operating systems.

    Step 1 – Requirements

    This Python installation required the GCC compiler on your system. Login to your server using ssh or shell access. Now, use the following command to install prerequisites for Python before installing it.

    yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel xz-devel 
    
    • Read: How to Use SSH to Connect Remote Linux Server

    Step 2 – Download Python 3.7

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

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

    Now extract the downloaded package.

    tar xzf Python-3.7.11.tgz 
    

    Step 3 – Install Python 3.7

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

    cd Python-3.7.11 
    ./configure --enable-optimizations 
    make altinstall 
    

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

    Now remove downloaded source archive file from your system

    rm /usr/src/Python-3.7.11.tgz 
    

    Step 4 – Check Python Version

    Check the latest version installed of python. Use command python3.7 instead of just python.

    python3.7 -V 
    
    Python 3.7.11
    
    Install python Python Python3 Python3.7
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleLinux Mint 19 (Tara) Released
    Next Article How to Install CentOS on Raspberry Pi

    Related Posts

    How to Find Django Install Location in Linux

    Updated:April 27, 20221 Min Read

    How To Install Python 3.10 on Debian 11/10

    2 Mins Read

    How to Install Python 3.10 on CentOS/RHEL 8 & Fedora 35/34

    Updated:February 12, 20223 Mins Read

    How To Install Python 3.10 on Ubuntu, Debian & Linux Mint

    Updated:April 22, 20222 Mins Read

    How to Switch Python Version in Ubuntu & Debian

    Updated:April 22, 20223 Mins Read

    Working with Python Functions

    6 Mins Read

    60 Comments

    1. Anil on May 11, 2022 6:56 am

      please advice, How do we uninstall pythan 3 from rhel 7 which was installed using the above steps.

      Reply
    2. Arman on July 16, 2021 6:37 pm

      Hi everyone!
      You MUST install the ‘xz-devel’ package for centos 7 before ./configure and make. This must be the sequence:

      yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel
      yum install xz-devel
      ./configure –enable-optimizations
      make altinstall

      Otherwise the installation would be incomplete.

      PLEASE ADD THIS TO THIS TUTORIAL!!!

      Reply
      • Rahul on July 17, 2021 1:27 am

        Thank you, Arman, tutorial has been updated accordingly.

        Reply
    3. senko on March 5, 2021 6:20 pm

      Can someone please guide how to install python 3 in centos 7 in an offline mode

      Reply
      • Wawan Skateboard on July 5, 2021 9:57 am

        no u can’t, u need to internet to download the required files. But, if you don’t have any access to the internet you could ask your friend to download the required files then you can copy it into your machine and install it there.

        Reply
    4. shakir ahmad on November 11, 2020 11:19 am

      File “/usr/src/python3/Python-3.7.2/Lib/runpy.py”, line 193, in _run_module_as_main
      “__main__”, mod_spec)
      File “/usr/src/python3/Python-3.7.2/Lib/runpy.py”, line 85, in _run_code
      exec(code, run_globals)
      File “/usr/src/python3/Python-3.7.2/Lib/ensurepip/__main__.py”, line 5, in
      sys.exit(ensurepip._main())
      File “/usr/src/python3/Python-3.7.2/Lib/ensurepip/__init__.py”, line 204, in _main
      default_pip=args.default_pip,
      File “/usr/src/python3/Python-3.7.2/Lib/ensurepip/__init__.py”, line 117, in _bootstrap
      return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
      File “/usr/src/python3/Python-3.7.2/Lib/ensurepip/__init__.py”, line 27, in _run_pip
      import pip._internal
      File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/__init__.py”, line 40, in
      File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py”, line 8, in
      File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py”, line 12, in
      File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/__init__.py”, line 6, in
      File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/completion.py”, line 6, in
      File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/base_command.py”, line 18, in
      File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/download.py”, line 38, in
      File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/utils/glibc.py”, line 3, in
      File “/usr/src/python3/Python-3.7.2/Lib/ctypes/__init__.py”, line 7, in
      from _ctypes import Union, Structure, Array
      ModuleNotFoundError: No module named ‘_ctypes’
      make: *** [altinstall] Error 1

      Reply
    5. Daniel Holmes on September 17, 2020 1:37 pm

      From my system it was missing zlib for the make to work. I had to additionally install this as a prerequisite

      yum install zlib-devel

      Reply
      • Rahul on September 18, 2020 2:08 am

        Thanks Daniel, Tutorial has been updated accordingly

        Reply
    6. ishahak on August 9, 2020 2:35 pm

      don’t we also want to delete the 194MB left in the Python-3.7.7 folder after the compilation?

      Reply
    7. Maureen on June 23, 2020 6:26 pm

      Successfully installed python 3.7.7 on Centos 7

      Reply
    8. DjBelu on June 5, 2020 11:46 am

      Hey Guys,

      Successfully install Python3.7 on REDHAT 7.7.

      Thanks you

      Reply
    9. trevaze on May 11, 2020 8:34 am

      Hi Rahul,

      Installed Python 3.7.7 using the steps in this article on RHEL 7.7
      python3.7 command is available after adding PYTHONHOME to path.
      I am unable to find command pip3.7 or pip3 or similar.
      Could you verify if pip is installed with this method Or do I have to install pip Or is there any additional config needed for pip3/3.7 command.

      Reply
    10. aaron on April 27, 2020 7:10 pm

      Looks like they’ve dropped support for 3.7… 🙁

      Reply
    11. Levior on January 18, 2020 9:17 am

      HI Rahul,

      We do already have Py3.6.5 which was installed through Anancond. Now we need Py3.7.1 so I’ve installed Py3.7.1 using the above steps . It seems like it got installed by python3 -V still showing 3.6.5 only, not 3.7.1.

      Can you help?

      Reply
      • Nataraj on January 5, 2021 12:55 pm

        Hi LEVIOR,

        Please go to the python py3.7.1 installed location , then run ./python –version and check

        Reply
    12. soma on December 16, 2019 10:08 am

      Succesfully Installed 3.7, but when i check version it is showing 2.7
      I tried python3 -V, but it is showing ” python3: command not found”.

      Below are the message after completing altinstall
      “setuptools in /usr/local/lib/python3.7/site-packages (40.8.0)”
      ” pip in /usr/local/lib/python3.7/site-packages (19.0.3)”.

      What else i need to do to make python3 as default.

      Reply
    13. mensa on December 6, 2019 7:27 pm

      hi,
      thanks for the article, i installed succesfully.
      however when is check the version using ‘python –version’ i still see Python 2.7.5

      Reply
      • Rahul on December 7, 2019 5:45 am

        Hi Mensa, Python 2.7 is the default version on your system. You can use Python 3 using following command:

        python3 -V
        
        Reply
    14. Edward on December 3, 2019 4:59 pm

      Succesfully installed python 3.7.4 on centos 6.10…
      Thanks

      Reply
    15. Edward on December 3, 2019 4:59 pm

      Succesfully install python 3.7.4 on Centos 7

      Reply
    16. pratheesh on November 19, 2019 4:13 am

      How can we uninstall Python3.7, which was installed using binaries/source code

      Reply
    17. Millan on October 20, 2019 1:12 am

      Ok, I’m bad. How do I run python? Does it come with the IDLE?
      But great guide!! It worked perfectly!

      Reply
    18. Abdulsalam Noman on October 18, 2019 5:32 pm

      Thanks so much.
      I install python 3.7.4 successfully with this method.

      Reply
    19. jacky on October 9, 2019 9:02 am

      add this to switch python2 and python3
      ln -sf /usr/local/bin/python3 /usr/bin/python

      Reply
    20. David on October 2, 2019 3:17 pm

      I just copy and paste the commands and it works! Thank you!

      Reply
    21. Christian on September 26, 2019 9:53 am

      Rahul, I got errors when making the make altinstall..
      .. So what to now I wonder…
      thanks but no cigar!

      Reply
      • Rahul on September 26, 2019 10:32 am

        Hi Christian, What error are you getting?

        Reply
    22. Antariksh on September 14, 2019 5:21 pm

      At Which location these steps install python3.7 , on running python3.7 -V returns: bash: python3.7: command not found

      Reply
      • Rahul on September 16, 2019 7:37 am

        Hi Antariksh,

        Does the installation succeed without any error?

        Reply
      • Chandu on September 25, 2019 7:46 am

        all steps in the blog are clear, ur installation goes into /usr/local/bin
        but you can directly use python3.7 -V , it should work.

        Reply
      • Prapoorna on October 15, 2019 12:07 am

        Hi Antarish,
        I ran into the same issue. Were you able to resolve and if so what’s your resolution?

        Reply
      • prapoorna on October 15, 2019 5:25 pm

        I have got it resolved by logging out of the server and logging back in. This was on an EC2.

        Reply
    23. Pram on August 28, 2019 5:47 pm

      Where is the pip installed , am unable to issue any command for pip install

      Reply
      • Chandu on September 25, 2019 7:44 am

        try pip3.7 install

        Reply
    24. Vincent on July 4, 2019 3:46 pm

      Just a tip for those who will encounter the same problem i had here on “make altinstall” line.
      “zipimport.zipimporterror can’t decompress data zlib not available”, you just have to install zlib-devel
      (:~$ sudo yum install zlib-devel)
      then run again the make altinstall command

      by the way Thank you very much for this article Sir Rahul!

      Reply
      • derek on August 11, 2019 12:48 pm

        Thanks for the heads up,

        Reply
    25. abdo on June 16, 2019 11:53 am

      thank you

      Reply
    26. imsparticus on June 7, 2019 12:54 pm

      Thankyou for such a thoughtful setup, cleaning up tar files , non destructive alinstall, such a breath of fresh air compared to most articles these days that assume so much about your environment.

      Reply
    27. Damien on May 24, 2019 10:45 am

      Thanks for the article, however under Centos 7 I got the following error:
      pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

      libssl-dev has been already installed:
      Package 1:openssl-devel-1.0.2k-16.el7_6.1.x86_64 already installed and latest version

      Reply
    28. Yuvaraju on April 29, 2019 2:52 pm

      Thankyou.. It’s working

      Reply
    29. Billy Zee on April 12, 2019 4:34 pm

      tk tcl tk-devel tcl-devel are needed if you want to import tkinter module

      Reply
    30. Billy Zee on April 10, 2019 3:54 pm

      readline-devel is also needed for interactive shell’s normal behaviour.

      Reply
    31. bob on April 4, 2019 3:42 am

      this worked for me on centos7 thank you

      Reply
    32. keven on April 3, 2019 2:16 pm

      hi,
      I have a question.When I “make altbinstall”,
      I can’t create the common file “/usr/local/bin/python3.7m”,because of the
      limited authority,so recipe for target “altinstall” failed.What should I do next?
      thank you very much.(Sorry,my English is poor,can you understand what I say?)

      Reply
    33. Mark T Ahlenius on March 25, 2019 5:41 pm

      Hi – thank you for this article. I am getting the following error (similar to one above) when doing the make altinstall on centos 10

      changing mode of /usr/local/bin/idle3.7 to 755
      rm /usr/local/lib/python3.7/lib-dynload/_sysconfigdata_m_linux_x86_64-linux-gnu.py
      rm -r /usr/local/lib/python3.7/lib-dynload/__pycache__
      /usr/bin/install -c -m 644 ./Misc/python.man \
      /usr/local/share/man/man1/python3.7.1
      if test “xupgrade” != “xno” ; then \
      case upgrade in \
      upgrade) ensurepip=”–altinstall –upgrade” ;; \
      install|*) ensurepip=”–altinstall” ;; \
      esac; \
      ./python -E -m ensurepip \
      $ensurepip –root=/ ; \
      fi
      Traceback (most recent call last):
      File “/usr/local/src/Python-3.7.2/Lib/runpy.py”, line 193, in _run_module_as_main
      “__main__”, mod_spec)
      File “/usr/local/src/Python-3.7.2/Lib/runpy.py”, line 85, in _run_code
      exec(code, run_globals)
      File “/usr/local/src/Python-3.7.2/Lib/ensurepip/__main__.py”, line 5, in
      sys.exit(ensurepip._main())
      File “/usr/local/src/Python-3.7.2/Lib/ensurepip/__init__.py”, line 204, in _main
      default_pip=args.default_pip,
      File “/usr/local/src/Python-3.7.2/Lib/ensurepip/__init__.py”, line 117, in _bootstrap
      return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
      File “/usr/local/src/Python-3.7.2/Lib/ensurepip/__init__.py”, line 27, in _run_pip
      import pip._internal
      File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/__init__.py”, line 40, in
      File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py”, line 8, in
      File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py”, line 12, in
      File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/__init__.py”, line 6, in
      File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/completion.py”, line 6, in
      File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/base_command.py”, line 18, in
      File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/download.py”, line 38, in
      File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/utils/glibc.py”, line 3, in
      File “/usr/local/src/Python-3.7.2/Lib/ctypes/__init__.py”, line 7, in
      from _ctypes import Union, Structure, Array
      ModuleNotFoundError: No module named ‘_ctypes’
      make: *** [altinstall] Error 1

      —

      I have tried the suggestion to do the “sudo yum install libffi-devel” but that did not make any difference.

      Any suggestions to get past this error?

      thank you

      ‘mark

      Reply
      • Rahul on March 27, 2019 4:10 am

        Try to install following package:

        yum install libffi-devel
        or
        sudo dnf install libffi-devel
        
        Reply
    34. Bun on March 16, 2019 9:43 am

      Hi Rahul,
      I have problem with installing packages wit pip inside an environment, i brief it as below:

      I get this error while installing some packages with pip3 inside an environment

      using centOS 7 with python 3.7.2 as parallel install.
      step to reproduce: (dependancies are installed)

      rm -rf /usr/local/lib/python3.7
      cd /root/
      wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
      tar -xzf Python-3.7.2.tgz
      cd Python-3.7.2
      ./configure –prefix=/usr/local –enable-shared –enable-optimizations LDFLAGS=”-Wl,-rpath /usr/local/lib”
      make
      make altinstall

      adduser a-user

      su – a-user
      /usr/local/lib/python3.7 -m venv user-envn
      source user-envn/bin/activate

      pi3 install –upgrade pip
      pip install pyusb==1.0.0

      result with error:

      Collecting pyusb==1.0.0
      Using cached https://files.pythonhosted.org/packages/8a/19/66fb48a4905e472f5dfeda3a1bafac369fbf6d6fc5cf55b780864962652d/PyUSB-1.0.0.tar.gz
      Complete output from command python setup.py egg_info:
      running egg_info
      creating pip-egg-info/pyusb.egg-info
      writing pip-egg-info/pyusb.egg-info/PKG-INFO
      writing dependency_links to pip-egg-info/pyusb.egg-info/dependency_links.txt
      writing top-level names to pip-egg-info/pyusb.egg-info/top_level.txt
      writing manifest file ‘pip-egg-info/pyusb.egg-info/SOURCES.txt’
      error: [Errno 13] Permission denied: ‘/usr/local/lib/python3.7/lib2to3/Grammar3.7.2.final.0.pickle’

      would you please help what has caused this and how to resolve? Thanks

      Reply
    35. Raj on March 13, 2019 2:20 am

      Add the follow steps for successful build.

      Ubuntu :
      sudo apt install libffi-dev

      CentOS:
      yum install libffi-devel

      Reply
    36. Billy Zee on March 6, 2019 1:51 pm

      It’s neccessary for installing pip.

      Reply
    37. Ş. Ozan on March 5, 2019 8:28 am

      Thanks for this post

      Reply
    38. tom on February 28, 2019 10:46 am

      Thanks it helped!

      Reply
    39. surya on February 19, 2019 6:46 am

      how install python3.7 IDLE on RHEL 7.4

      Reply
    40. Shane on September 19, 2018 6:08 am

      yum-builddep python36

      Reply
    41. Ciro on August 21, 2018 7:12 pm

      Instalou sem erros, porem quando procuro na pasta bin junto com as outras versões não aparece.
      E quando coloco python3.7 –version mostra como não instalado.

      Reply
    42. Alexandr on July 31, 2018 11:19 am

      # python3.7 -V
      bash: python3.7: not found

      then

      # whereis python
      python: /usr/bin/python /usr/bin/python2.7 /usr/bin/python2.7-futurize /usr/bin/python2.7-pasteurize /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/local/bin/python3.7m /usr/local/bin/python3.7 /usr/local/bin/python3.7m-config /usr/local/lib/python3.7 /usr/include/python2.7 /usr/share/man/man1/python.1.gz /usr/src/Python-3.7.0/python

      and move label to directory which you need like it

      cp /usr/src/Python-3.7.0/python /usr/bin/python3.7

      Reply
      • Bharathi on March 23, 2021 10:53 am

        did you get this error? Please help to fix.

        [[email protected] Python-3.7.9]# python3.7 -V
        bash: python3.7: command not found
        [[email protected] Python-3.7.9]# whereis python
        python: /usr/bin/python /usr/bin/python2.7 /usr/bin/python2.7-config /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/local/bin/python3.7m /usr/local/bin/python3.7 /usr/local/bin/python3.7m-config /usr/local/lib/python3.7 /usr/include/python2.7 /usr/share/man/man1/python.1.gz /usr/src/Python-3.7.9/python
        [[email protected] Python-3.7.9]# cp /usr/src/Python-3.7.0/python /usr/bin/python3.7
        cp: cannot stat ‘/usr/src/Python-3.7.0/python’: No such file or directory

        Reply
    43. Alexandr on July 31, 2018 11:12 am

      try yum install libffi-devel if you have Python3: ImportError: No module named ‘_ctypes’ when using Value from module multiprocessing

      Reply
      • Amirhossein on January 14, 2019 5:55 pm

        Thank you

        Reply
    44. Eugene Taradayko on July 24, 2018 7:56 am

      You have to add following requirement too – yum install libffi-devel
      And thanks for the article

      Reply
    45. Eugene on July 24, 2018 7:50 am

      Just thank you for useful article!

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    • (Resolved) Please install all available updates for your release before upgrading
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.