How to Install Python 3.9 on CentOS 7

One of the most popular programming languages is Python, used in everything from low-level scripting to high-level application development. As of 2020, Python 3 has taken the place of its predecessor, Python 2. Python 3 can be installed on most modern operating systems, including Windows and CentOS. In this article, we will outline how to install Python 3.9 on CentOS 7.

Installing Python Package Manager PIP

  1. Before we can install the Python package manager, PIP, we need to enable additional software repositories using the following command:
    sudo yum install epel-release
  2. Next, install PIP using the following command:
    sudo yum install python-pip
  3. Finally, confirm that the installation was successful using the following command:
    pip --version
  4. If successful, the system should display the PIP version as well as your current Python version.

Installing Python 3.9 

Now that we have PIP installed, we can proceed with installing the latest version of Python, 3.9. 

  1. Before installing Python you will first need to install the requisite software packages using the following command: 
    sudo yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel
  2. Once that is done, navigate to the /usr/local/src directory:
    cd /usr/local/src
  3. Download the latest version of Python using the wget command as follows:
    wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
  4. Once the file is downloaded, extract it using the following command:
    tar -xvf Python-3.9.6.tgz
  5. Once the file has extracted, move into the directory that was created
    cd Python-3.9.6
  6. Configure the installation using the following command:
    ./configure —-prefix=/usr/local/
  7. Run the following command:
    sudo make
  8. Next, build Python using the following command:
    sudo make altinstall
  9. After the installation process has finished, confirm the version using the following command:
    python3.9 --version

Congratulations, you have successfully installed Python 3.9 and PIP!

Trust your website to an industry leader in website hosting. InMotion Hosting offers secure web hosting with 99.99% uptime, 24/7/365 technical support, and 100% money-back guarantee.
InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

6 thoughts on “How to Install Python 3.9 on CentOS 7

  1. Hi,
    I follow your instructions all was well but when i used command “sudo make” then got fail here :

    Could not import runpy module
    Traceback (most recent call last):
    File “/home/centos/Python-3.9.6/Lib/runpy.py”, line 15, in
    import importlib.util
    File “/home/centos/Python-3.9.6/Lib/importlib/util.py”, line 2, in
    from . import abc
    File “/home/centos/Python-3.9.6/Lib/importlib/abc.py”, line 17, in
    from typing import Protocol, runtime_checkable
    File “/home/centos/Python-3.9.6/Lib/typing.py”, line 21, in
    import collections
    SystemError: returned NULL without setting an error
    generate-posix-vars failed
    make: *** [pybuilddir.txt] Error 1

    any solution to this ?

    1. Hello Ali – Sorry for the issue. This issue happens if the installation was canceled in between or an old environment was not properly removed and was overwritten. (https://stackoverflow.com/questions/44463879/could-not-import-runpy-module#:~:text=This%20happens%20if%20the%20installation,to%20re%2Dinstall%20the%20environment.&text=Save%20this%20answer.,-Show%20activity%20on). They suggest reinstalling the environment. If you continue to have issues, please contact our live support team for help on your server.

  2. Once you have the py3.9 installed, how do you register a flask app in cpanel to use the new install rather than the detail 2.7?

    1. The guide was missing a step where you run the “make” command, I have added it as Step 5 above. Other than that it should work. Keep in mind that if you are installing on a VPS, you may not see the installation in cPanel, and python 3.9 is already available on our Shared Hosting plans.

  3. Thank you very much. Just want to add that i didn’t understand the step 4 and stuck in it untill i moved into Python-3.9.6 directory.

    1. Thanks for the feedback! I’m glad to hear that you found the article helpful and were able to sort out the confusion. We’ll review the wording on step 4 and see what we can do to make it a bit clearer for future readers.

Was this article helpful? Join the conversation!