Installing Python 2.7.13 on CentOS 6.5

This post describes how to install python 2.7 from source without affecting the existing python installation. It'll install the python2.7 in a separate location other than the standard location in CentOS.

Install required packages: 

yum -y update yum groupinstall -y 'development tools'

yum install -y gcc zlib-devel bzip2-devel openssl-devel xz-libs wget



Download and extract python source:

wget http://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz 
xz -d Python-2.7.13.tar.xz 
tar -xvf Python-2.7.13.tar


Create a directory where to install python e.g. ~/localpython:

mkdir /home/nayan/localpython


Go to extracted python source directory:

cd Python-2.7.13


Run the configure:

./configure --prefix=/home/nayan/localpython --enable-shared


Compile and install it: 

make make altinstall

Check if python installed by running python2.7


Make a link to Python library path:

On 32 bit OS
ln -s /home/nayan/localpython/lib/libpython2.7.so.1.0 /usr/lib/libpython2.7.so.1.0
 

On 64 bit OS
ln -s /home/nayan/localpython/lib/libpython2.7.so.1.0 /usr/lib64/libpython2.7.so.1.0


Export the localpython path so that python2.7 can be run from anywhere:

export PATH="/home/nayan/localpython/bin:$PATH"


Install pip:

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


That's it! It' recommended to create a virtual environment and run python project using virtual environment. To install virtual environment:

pip2.7 install virtualenv

Create a virtual environment named venv:
virtualenv venv

Comments


  1. Thanks for sharing amazing information about python .Gain the knowledge and hands-on experience in python online training

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete

Post a Comment

Popular posts from this blog

Run tasks in background in Spring

Conditional field inclusion in Jackson and Spring Boot

How to configure Wildfly 10 to use MySQL