Monday, 5 December 2016

Installing Python on Linux without disrupting existing one

Python is important package that comes installed on Linux systems. Corrupting the pre-installed version makes many of the packages non-usable. I could not yum after the pre-installed version of Python was corrupt.

Here is how you can install a version of Python on Linux operating system, keeping the pre-installed one safe. Here, we use CentOS 6.4 version, which is a pretty old release.

Issues solved by this document

pip is an important module you need while working on Python. Following are the errors I have faced while trying to install pip module and this document helps you in solving them too:
  • zipimport.ZipImportError: can't decompress data; zlib not available

    [root@localhost tmp]# python2.7 
    Traceback (most recent call last):
      File "", line 20061, in 
      File "", line 194, in main
      File "", line 82, in bootstrap
        import pip
    zipimport.ZipImportError: can't decompress 
    data; zlib not available

  • There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available.

    [root@localhost tmp]# python2.7 
    pip is configured with locations that require TLS/SSL, 
    however the ssl module in Python is not available.
    Collecting pip
      Could not fetch URL
    ip/: There was a problem confirming the ssl certificat
    e: Can't connect to HTTPS URL because the SSL module i
    s not available. - skipping
      Could not find a version that satisfies the requirem
    ent pip (from versions: )
    No matching distribution found for pip
    [root@localhost tmp]#

Verify the current version

You may use python --version command on the terminal to find the current version.

Installing a different version

  1. You may download a version you would need to install from Python Download. By default, Python comes as tarball for Linux.
  2. Once you have the tarball downloaded, copy it to a location where we extract and do the installation. Here, I copied the 2.7.12 version to /tmp. Use the version which is available for your platform and remember to use the commands accordingly.
  3. Extract tarball and change directory to the extracted folder.
    tar xvf Python-2.7.12.tar.xz
    cd Python-2.7.12
  4. Install required Linux packages. gcc is a utility for compiling and installing Python from source, zlib-devel and openssl-devel are required to avoid errors while installing pip module at a later stage. You would need to be root or a sudoer to install these packages:
    yum install gcc
    yum install zlib-devel
    yum install openssl-devel
  5. Run configure with option to export shared libraries. This is necessary if you would need to use pyinstaller module.
    ./configure --enable-shared
  6. Generate the build:
  7. Install Python without replacing the existing version. Using altinstall option will help you to use the new installation with version suffix during execution. e.g. python2.7 --version:
    make altinstall
  8. Make a link to Python library path:
  • On 32 bit OS
    ln -s /usr/local/lib/ /usr/lib/
  • On 64 bit OS
     ln -s /usr/local/lib/ /usr/lib64/

 Installing pip module

Here is how you may get pip for the Python version you have just installed:
  1. Running is a better way to install pip. file is available at pip module listing.
  2. Run with the version of Python you have installed. For example:
    This installs a pip utility which you can use with suffix. e.g. pip2.7 install pyinstaller 


  1. Thank you very much James. I got the same problem and your post really helped!

  2. Thank you! This is awesome. So simple, yet impossible to get a straight procedure like this anywhere else

  3. This is great and works really well. However if this is meant to install python3.6, the correction to step 8 should read
    ln -s /usr/local/lib/ /usr/lib64/

    Thanks James!

  4. Thanks for sharing. This helped.

  5. Thank you so much! I follow this for python 3.6 and it worked perfectly.

  6. Does your blog have a contact page? I’m having problems locating it but, I’d like to shoot you an email. I’ve got some recommendations for your blog you might be interested in hearing.
    AWS Training in Chennai |Best Amazon Web Services Training in Chennai
    Best AWS Amazon Web Services Training in Chennai | AWS Training in Chennai cost
    No.1 AWS Training in Chennai | Amazon Web Services Training Institute in Chennai

  7. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article. thank you for sharing such a great blog with us.
    microsoft azure training in bangalore
    rpa training in bangalore
    rpa training in pune
    best rpa training in bangalore

  8. This looks absolutely perfect. All these tiny details are made with lot of background knowledge. I like it a lot. 
    Best Devops training in sholinganallur
    Devops training in velachery
    Devops training in annanagar
    Devops training in tambaram

  9. My developer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s trying none the less. I’ve been using Movable-type on several websites for about a year and am anxious about switching to another platform. I have heard great things about Is there a way I can transfer all my Word Press posts into it? Any help would be appreciated.
    python training Course in chennai
    python training in Bangalore
    Python training institute in bangalore

  10. The post is written in very a good manner and it entails many useful information for me. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept.

    DevOps Training in Bangalore

    DevOps Training in Bangalore

    DevOps Training in Bangalore

    DevOps Training in Marathahalli

    DevOps Training in Pune

    DevOps Online Training-gangboard

  11. Thanks for valuable information. I found it very useful.

  12. Home Mart is a site about Home Improvement, Furniture, Home Appliances and many more.
    Check out the best
    furniture sale
    Dog Cages
    bedroom furniture nz