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

  • 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 get-pip.py 
    pip is configured with locations that require TLS/SSL, 
    however the ssl module in Python is not available.
    Collecting pip
      Could not fetch URL https://pypi.python.org/simple/p
    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:
    make
  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/libpython2.7.so.1.0 /usr/lib/libpython2.7.so.1.0
  • On 64 bit OS
     ln -s /usr/local/lib/libpython2.7.so.1.0 /usr/lib64/libpython2.7.so.1.0

 Installing pip module

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

33 comments:

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

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

    ReplyDelete
  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/libpython3.6m.so.1.0 /usr/lib64/libpython3.6m.so.1.0

    Thanks James!

    ReplyDelete
  4. Thanks for sharing. This helped.

    ReplyDelete
    Replies
    1. Thank you for helping people get the information they need. Great stuff as usual. Keep up the great work.
      Real Estate Lawyer in Brampton

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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

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

    ReplyDelete
  10. Thanks for valuable information. I found it very useful.

    ReplyDelete
  11. 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

    ReplyDelete
  12. For Devops Training in Bangalore Visit: Devops Training in Bangalore

    ReplyDelete
  13. Marijuana—also called weed, herb, pot, grass, bud, ganja, Mary Jane, and a vast number of other slang terms—is a greenish-gray mixture of the dried flowers of Cannabis sativa.

    The main active chemical in marijuana is THC (delta-9-tetrahydrocannabinol), the psychoactive ingredient. The highest concentrations of THC are found in the dried flowers, or buds. When marijuana smoke is inhaled, THC rapidly passes from the lungs into the bloodstream and is carried to the brain and other organs throughout the body. THC from the marijuana acts on specific receptors in the brain, called cannabinoid receptors, starting off a chain of cellular reactions that finally lead to the euphoria, or "high" that users experience. Feeling of a relaxed state, euphoria, and an enhanced sensory perception may occur. With higher THC levels in those who are not used to the effects, some people may feel anxious, paranoid, or have a panic attack.
    Cannabis plant used for medical or recreational purposes. The main psychoactive part of cannabis is tetrahydrocannabinol, one of the 483 known compounds in the plant, including at least 65 other cannabinoids. 
    buy real weed online
    how to buy weed online
    buy legal weed online
    buy recreational weed online
    buy weed edibles online
    can i buy weed online
    buy medical weed online
    buy weed online canada
    buying weed online reviews
    buy weed online legit
    buy weed online without medical card
    buy weed seeds online canada
    order marijuana online
    order marijuana seeds online
    how to order marijuana online
    order marijuana online without a medical card
    can you order medical marijuana online
    order marijuana online

    ReplyDelete
  14. very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information.Thanks for sharing this valuable information to our vision.

    AWS training in Chennai

    AWS Online Training in Chennai

    AWS training in Bangalore

    AWS training in Hyderabad

    AWS training in Coimbatore

    AWS training

    AWS online training

    ReplyDelete
  15. Thanks for shared that blog with us. If anyone here searching Python Exception Class then visit Coding Dolphin.

    ReplyDelete
  16. Thanks for sharing this amazing article. This was truly informative.

    Buy Custom Website

    ReplyDelete
  17. Thanks for Sharing a Very Informative Post & I read Your Article & I must say that is very helpful post for us.
    Data Science Course in Pune

    ReplyDelete
  18. Your article is very informative and has a lot of information. I really like your effort, keep posting.
    Moreover, if you are looking for professional law dissertation proposal services, check this.

    ReplyDelete
  19. Such an very helpful and amazing post thanks for sharing with us.
    Buy Logo Design

    ReplyDelete
  20. It is surely an amazing post, thank you so much for the share. Also, visit our website if you are looking to buy amazing products in Pakistan:

    Cheezain

    ReplyDelete

  21. It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read. Best cheat sheet service provider.

    ReplyDelete

  22. Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from youftp ports

    ReplyDelete
  23. JackpotCity Casino Site - Lucky Club Live
    JackpotCity Casino is a trusted online gambling platform luckyclub.live offering a fantastic selection of slots and live dealer games. Join today to receive your welcome package  Rating: 4.8 · ‎13 votes

    ReplyDelete
  24. Housing Disrepair Claims connects potential claimants like you with our experienced panel of pre-screened law firms and solicitors and produces clear, thorough information on every claim type in the UK.
    Housing Disrepair Claims

    ReplyDelete
  25. They both are used for the same services then what's the purpose.
    If anyone want assistance with writing then click the link Law Coursework Help

    ReplyDelete
  26. Once each the player and the banker obtain the playing cards, a complete point is displayed on the display screen. In an occasion the place either of the hands has a complete of eight or 9, it is considered ‘natural’ and no additional playing cards are dealt. The one 카지노 that scores some extent closed to 9 is asserted because the winner and if each hands complete to the same quantity, it’s a tie.

    ReplyDelete