Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Tutorials»How to Install Python 2.7.18 on CentOS/RHEL 7/6 and Fedora 32/31

    How to Install Python 2.7.18 on CentOS/RHEL 7/6 and Fedora 32/31

    By RahulMay 23, 20202 Mins Read

    Today, I was trying to install an application on my CentOS 7.4 system which required Python >= 2.7.10, but there are Python 2.7.5 installed, which we can’t remove as other applications depend on it. This tutorial will help you to install Python 2.7.18 without removing older versions.

    Advertisement

    1. Prerequisites

    Firstly make sure that you have GCC package installed on your system. Use the following command to install GCC if you don’t have it installed.

    yum install gcc openssl-devel bzip2-devel   # On CentOS systems 
    dnf install gcc openssl-devel bzip2-devel   # On Fedora systems 
    

    2. Download Python 2.7

    Download Python using following command from 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/2.7.18/Python-2.7.18.tgz
    

    Extract downloaded archive using tar command.

    tar xzf Python-2.7.18.tgz
    

    3. Install Python 2.7

    Now run the following commands to compile Python 2.7 and install on your system using altinstall.

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

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

    4. Check Python Version

    Check the latest version installed of python using below command. During this installation, the latest Python binary was installed on path /usr/local/bin/python2.7. The existing binary was located under /usr/bin.

    /usr/local/bin/python2.7 -V
    
    Python 2.7.18
    

    Warning: Do not overwrite or link the original Python binary, This may damage your system.

    5. Install PIP

    PIP is a useful utility to install and manage Python modules. Let’s install the PIP for the installed Python version.

    curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
    python2.7 get-pip.py
    

    Python Python2.7
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install Python 3.11 on Amazon Linux 2

    An Introduction to the “./configure” Command: Compiling Source Code in Linux

    Installing Python 3.11 on Debian Linux

    How To Install Python 3.11 on Debian 11/10

    View 48 Comments

    48 Comments

    1. lince on January 18, 2021 4:43 pm

      Seems like you’re missing “yum install make” as dependency too 🙂
      (at least i got an error in a centos 7 container)

      Reply
    2. Niculescu Tudor on August 26, 2020 9:39 am

      Please note that the command
      curl “https://bootstrap.pypa.io/get-pip.py” -o “get-pip.py”
      does not work anymore. User gets error
      curl: (35) Peer reports incompatible or unsupported protocol version.
      I think this error is given by the fact that the site “https://bootstrap.pypa.io/get-pip.py” does not accept TLS version older than 1.2.
      Workaround was to give the command on a different machine that had TLS1.2 and copy the downloaded get-pip.py file from that machine to the CentOS machine on location /usr/src/Python-2.7.16
      after this step, give the last command from the webBlog.
      python2.7 get-pip.py

      Reply
    3. Alvaro Diaz on July 18, 2019 8:17 am

      Please beware, this doesn’t work on Centos 7, make alt install will break default python 2.7.5 installation.

      Reply
    4. Beta on July 14, 2019 4:02 pm

      DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t btained after that date. A future version of pip will drop support for Python 2.7.

      WHAT? when i type python -V im still on 2.6 then it say that

      Reply
    5. Samuel on July 1, 2019 4:44 am

      Hello, and how can I uninstall this? Since I can only use it using python2.7
      I want to uninstall it

      Reply
    6. suchita on May 29, 2019 7:28 pm

      >>> import boto
      >>> boto.version
      Traceback (most recent call last):
      File “”, line 1, in
      AttributeError: ‘module’ object has no attribute ‘version’
      >>>

      how to fix this error

      Reply
      • Rahul on May 31, 2019 6:11 am

        Hi Suchita, Try with capital V in version:

        >>> import boto
        >>> boto.Version

        Reply
    7. V on May 11, 2019 1:52 pm

      an error in the tutorial.
      search for: tar xzf Python-2.7.14.tgz
      replace by: tar xzf Python-2.7.15.tgz

      Reply
      • Rahul on May 13, 2019 5:35 am

        Thanks V. Article has been updated for the latest version installation of Python 2.7.

        Reply
    8. KB on April 19, 2019 4:06 am

      Im getting this error, is there any way to bypass certificate checking?

      [[email protected] Python-2.7.15]# python2.7 get-pip.py
      DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7.
      Collecting pip
      Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)’),)’: /simple/pip/
      Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)’),)’: /simple/pip/
      Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)’),)’: /simple/pip/
      Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)’),)’: /simple/pip/
      Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)’),)’: /simple/pip/
      Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=’pypi.org’, port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)’),)) – skipping
      Could not find a version that satisfies the requirement pip (from versions: )
      No matching distribution found for pip
      Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=’pypi.org’, port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)’),)) – skipping

      Reply
    9. Jeremy on August 10, 2018 3:19 pm

      Works well with RHEL7. I was having issues installing Python 2.7.14 onto a RHEL7 system that had Python 2.7.5 as it’s native install.

      Your concise instructions helped show how “make altinstall” was the correct solution to avoid overwriting the native Python 2.7.5 install.

      Reply
    10. MarSoft on April 18, 2018 9:03 am

      Two additions:

      1. altinstall role is not properly described. Altinstall means “don’t overwrite $PREFIX/bin/python symlink”; in our case system-default Python is installed under /usr/bin/python (PREFIX=/usr), while we install 2.7.14 Python under /usr/local/bin/python (PREFIX=/usr/local).
      So if we use `make install` then we will create `/usr/local/bin/python`, without overwriting `/usr/bin/python`. And `/usr/local/bin` has higher priority than `/usr/bin` resulting in new Python version being used for `python` command, and this may break some system-wide stuff. Although scripts with hard-coded `#!/usr/bin/python` in shebang will still use old python version.

      2. No need to download `get-pip.py` script because Python 2.7.14 has built-in `ensurepip` module. It is enough to enter `python2.7 -m ensurepip` to install pip.

      Reply
    11. shobhit on April 4, 2018 6:02 am

      Hi Rahul ,
      do u have any idea how to install 32 bit python on 64 bit rhel 6.8 .

      Reply
    12. Brent on January 31, 2018 9:35 am

      All worked and many thanks for publishing this!

      Reply
    13. rad on January 9, 2018 11:12 pm

      Any way I can make a binary i.e. rpm with this and then move it to prod? I don’t want to compile stuff on prod servers.

      Reply
    14. himanshu chauhan on October 24, 2017 9:31 am

      python2.7 is not a valid command

      /usr/local/bin/python2.7 –version ,This path need to be added to PATH

      /usr/local/bin/python2.7 –version

      Reply
    15. nandan on October 10, 2017 7:57 pm

      what is the latest python version which supports RHEL 6.8 ?

      Reply
    16. Madhu on August 25, 2017 9:50 am

      I am getting error in the last command python2.7 get-pip.py
      The following is the error msg
      [[email protected] Python-2.7.13]$ python2.7 get-pip.py
      Collecting pip
      Using cached pip-9.0.1-py2.py3-none-any.whl
      Collecting wheel
      Using cached wheel-0.29.0-py2.py3-none-any.whl
      Installing collected packages: pip, wheel
      Exception:
      Traceback (most recent call last):
      File “/tmp/tmpGCg2kV/pip.zip/pip/basecommand.py”, line 215, in main
      status = self.run(options, args)
      File “/tmp/tmpGCg2kV/pip.zip/pip/commands/install.py”, line 342, in run
      prefix=options.prefix_path,
      File “/tmp/tmpGCg2kV/pip.zip/pip/req/req_set.py”, line 784, in install
      **kwargs
      File “/tmp/tmpGCg2kV/pip.zip/pip/req/req_install.py”, line 851, in install
      self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
      File “/tmp/tmpGCg2kV/pip.zip/pip/req/req_install.py”, line 1064, in move_wheel_files
      isolated=self.isolated,
      File “/tmp/tmpGCg2kV/pip.zip/pip/wheel.py”, line 345, in move_wheel_files
      clobber(source, lib_dir, True)
      File “/tmp/tmpGCg2kV/pip.zip/pip/wheel.py”, line 316, in clobber
      ensure_dir(destdir)
      File “/tmp/tmpGCg2kV/pip.zip/pip/utils/__init__.py”, line 83, in ensure_dir
      os.makedirs(path)
      File “/usr/lib64/python2.7/os.py”, line 157, in makedirs
      mkdir(name, mode)
      OSError: [Errno 13] Permission denied: ‘/usr/lib/python2.7/site-packages/pip’
      [[email protected] Python-2.7.13]$

      Reply
      • Soham on November 1, 2017 8:00 am

        Use –user along with command

        python2.7 get-pip.py –user

        Reply
    17. Eugene on August 6, 2017 9:51 am

      What about pip for this version of python?

      Reply
      • Rahul K. on August 6, 2017 10:39 am

        I Eugene, I have added the last step to installed PIP for the installed Python version.

        Reply
    18. Ricou on July 19, 2017 2:56 pm

      I installed the version 2.7.5 but i don’t find the file python2.7. I d’ont understand.

      Reply
      • Manoj Dhiman on August 10, 2017 7:35 am

        cmd type = python

        start your programing

        Reply
    19. Patty Nall on July 7, 2017 9:35 pm

      These steps are simple and easy to replicate across hosts. Worked like a charm. Thanks.

      Reply
    20. Jeff Scott on July 5, 2017 9:12 pm

      python2.7 -V didn’t work. says cannot find it.

      I can run “python” from “/usr/src/Python2.7.13/” and I get the version 2.7.3 but running python2.7 does nothing.

      What went wrong? Do I need to run install-sh after doing the “make altinstall” command?

      Please help. I’m not familiar with Oracle Linux, I’m used to Ubuntu Server and I’m floundering a bit here.

      Reply
    21. Imran on May 16, 2017 2:35 am

      Excellent

      Reply
    22. Denis on April 10, 2017 12:06 pm

      thx drom Russia

      Reply
    23. Ashik on April 10, 2017 7:58 am

      Your article helps me to install…

      After the installation we are getting the below error when we try to run a command,

      [[email protected] home]# vdetect –reseller=xyz
      AH00112: Warning: DocumentRoot [/home/*/public_html/web1] does not exist
      AH00112: Warning: DocumentRoot [/home/*/public_html/krk.*.com] does not exist
      AH00112: Warning: DocumentRoot [/home/*/public_html/home/cistrons/public_html/demo] does not exist
      AH00112: Warning: DocumentRoot [/home/*/public_html/web1] does not exist
      AH00112: Warning: DocumentRoot [/home/*/public_html/home/innosysc/public_html/demo] does not exist
      AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/conf/httpd.conf:107656
      AH00112: Warning: DocumentRoot [/home/*/public_html/paypal-singin] does not exist
      AH00112: Warning: DocumentRoot [/home/*/public_html/paypal-singin] does not exist
      Traceback (most recent call last):
      File “/root/bin/vdetect”, line 618, in
      signatures = ApplicationSignature.get_xml_signatures_from_url(opts.sigloc, opts.useragent)
      File “/root/bin/vdetect”, line 218, in get_xml_signatures_from_url
      return cls.get_xml_signatures_from_string(urllib2.urlopen(req).read())
      File “/usr/local/lib/python2.7/urllib2.py”, line 154, in urlopen
      return opener.open(url, data, timeout)
      File “/usr/local/lib/python2.7/urllib2.py”, line 429, in open
      response = self._open(req, data)
      File “/usr/local/lib/python2.7/urllib2.py”, line 447, in _open
      ‘_open’, req)
      File “/usr/local/lib/python2.7/urllib2.py”, line 407, in _call_chain
      result = func(*args)
      File “/usr/local/lib/python2.7/urllib2.py”, line 1228, in http_open
      return self.do_open(httplib.HTTPConnection, req)
      File “/usr/local/lib/python2.7/urllib2.py”, line 1198, in do_open
      raise URLError(err)
      urllib2.URLError:
      [[email protected] home]#

      Reply
    24. Gaurav on March 21, 2017 5:02 am

      It about Windows 7, It doesn’t have python 2.7 and I want to install python 2.7.13 first so how would I do this using batch file? Assume all setups are placed on common location.

      Reply
    25. Tank on March 20, 2017 7:15 pm

      Works. Thank you

      Reply
    26. Ashish on November 2, 2016 7:07 pm

      make altinstall command is failing with the following message:

      make: *** No rule to make target ‘altinstall’. Stop

      Reply
      • Johnny H on February 8, 2019 2:51 am

        Please install gcc and try again

        Reply
    27. Ed Jaffe on June 5, 2016 5:14 am

      Installed like a charm on an IBM Mainframe. Thanks!

      Reply
    28. jcheang on May 17, 2016 7:30 am

      Hi,

      This works perfectly.
      Could you show how to install pyodbc to this python2.7 altinstall dir?
      By default running the pyodbc rpm, it gets install to the python 2.6 dir.

      Please advise. thanks.

      Reply
    29. avinash on April 5, 2016 4:01 pm

      works gr8

      Reply
    30. Shekhar on March 4, 2016 1:49 pm

      Worked as a charm for me on Centos 6.4. Thank you very for the article.

      Reply
    31. Weo on February 11, 2016 12:54 pm

      Thanks.

      Reply
    32. NoMoBama on December 19, 2015 2:43 am

      Just a heads up, if you are on centos/rhel 7, where python2.7.5 is the default, the altinstall option for any other python2.7 version (2.7.11 for instance) will break your installation as it writes to the same /usr/lib/python2.7 directory and destroys the yum modules. I am sure there is a way around this, but I just encountered this issue and it took rebuilding yum from a few RPMs just to get my system back to normal.

      Reply
      • tony c on June 10, 2016 11:33 am

        How did you do this? I did the same thing and would like to get back to the original situation?

        Thanks!

        Reply
      • aenagy on August 16, 2017 3:14 am

        How did you fix this? Is this why pip will not install?

        # curl “https://bootstrap.pypa.io/get-pip.py” -o “get-pip.py”
        % Total % Received % Xferd Average Speed Time Time Time Current
        Dload Upload Total Spent Left Speed
        100 1558k 100 1558k 0 0 1172k 0 0:00:01 0:00:01 –:–:– 1174k
        # python2.7 get-pip.py
        Traceback (most recent call last):
        File “get-pip.py”, line 20061, in
        main()
        File “get-pip.py”, line 194, in main
        bootstrap(tmpdir=tmpdir)
        File “get-pip.py”, line 82, in bootstrap
        import pip
        zipimport.ZipImportError: can’t decompress data; zlib not available
        [[email protected] src]#

        Reply
        • Will on June 5, 2018 5:14 am

          RUN “yum install gcc openssl-devel bzip2-devel” first! then download and install python

          Reply
    33. RJ on June 22, 2015 11:49 am

      Great article! Easy to read and does what it supposed to do. I tried it on Centos6.6

      Reply
    34. doublenain on May 29, 2015 8:54 am

      More quickly

      yum install centos-release-SCL
      yum install python27
      scl enable python27 bash

      Reply
      • Nurlan on August 8, 2017 9:03 am

        Thank YOu!

        Reply
      • Mannu Thareja on January 28, 2019 10:13 pm

        Thanks, how to install pip?

        Reply
    35. name on December 3, 2014 11:29 pm

      thanks, great work!

      just a question from a novice, how do i now -use- this altinstall instead of the standard version
      e.g. when running plexconnect.py?

      Reply
    36. unais on September 27, 2013 4:26 am

      Hello Rahul,

      I have installed Python 2.7 on centos 5 from source code. Python 2.4 is already there in centos 5. Could you please help me to uninstall Python 2.7 so that I can reinstall it with yum.

      Thanks in advance

      Reply
    37. Brian on September 21, 2013 2:49 am

      Worked perfectly and put into simple steps. Very good for someone new to linux. Thanks!

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • sleep Command in Linux with Examples
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    • What is a Orphan Process in Unix/Linux
    • How To Display Warning Message to Unauthorized SSH Access
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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