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.

Advertisement

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 

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
Share.

60 Comments

  1. 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!!!

    • Wawan Skateboard on

      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.

  2. 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

  3. 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

  4. 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.

  5. 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?

  6. 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.

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

  8. 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!

  9. 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.

  10. 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

  11. 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?)

  12. Mark T Ahlenius on

    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

  13. 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

  14. 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.

  15. # 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

    • did you get this error? Please help to fix.

      [root@ip-172-31-27-145 Python-3.7.9]# python3.7 -V
      bash: python3.7: command not found
      [root@ip-172-31-27-145 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
      [root@ip-172-31-27-145 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

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

  17. Eugene Taradayko on

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

Leave A Reply

Exit mobile version