in ,

How to Download and Install Python 2.7 on centos 6+

Hello Everyone,

The CentOS 6.4 system comes stock with Python 2.6. As I have learned, you do not want to remove/overwrite 2.6 as other system tools use it. So you will want to install it as an “alternate” version.

To find our which version of python do you have and the location of the python file.

$ which python 
/usr/local/bin/python
Do not use $ just put the command Which python , It will show the exact path of the python.

$ python -V
Python 2.7.3

This command will show you the version of the python. Which you have it on your Server.

First download Python 2.7 from the Python Org download website http://www.python.org/download/.  At the time of this writing, the latest release is Python 2.7.6. All of these instructions assume you are doing these as root. You can alternatively use sudo.

NOTE: the final step is to use make altinstall. This is important.

In order to compile Python you must first install the development tools:

yum groupinstall "Development tools"

You also need a few extra libs installed before compiling Python or else you will run into problems later when trying to install various packages:

yum install zlib-devel
yum install bzip2-devel
yum install openssl-devel
yum install ncurses-devel
yum install sqlite-devel

Download, compile and install Python

Installing python 2.7 on centos
Installing python 2.7 on centos

The –no-check-certificate is optional

cd /opt
wget --no-check-certificate https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure --prefix=/usr/local
make && make altinstall

It is important to use altinstall instead of install, otherwise you will end up with two different versions of Python in the filesystem both named python.

(Depending on your version of wget, you may need to add the –no-check-certificate option to the wget command line.)

After running the commands above your newly installed Python 2.7.6 interpreter will be available as /usr/local/bin/python2.7 and the system version of Python 2.6.6 will be available as /usr/bin/python and /usr/bin/python2.6.

If things don’t look right, you might need to create a symbolic link in /usr/local/bin

cd /usr/local/bin
ls -ltr python*

WARNING: don’t do this before checking the $PATH for root. if it has /usr/local/bin before /usr/bin, it will see python2.7 first i.e.

root@openstack h2o]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

If you add this link, do a “which python” for the user and for root. If root is pointing to /usr/local/bin/python, remove the link you just added, and figure out something else.

ln -s /usr/local/bin/python2.7 /usr/local/bin/python

If still you are getting issue then you can visit this link:-
https://github.com/h2oai/h2o/wiki/Installing-python-2.7-on-centos-6.3.-Follow-this-sequence-exactly-for-centos-machine-only

Thank you for reading the Tutorial.

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%