Install Python 2.7 on CentOS

Problem

How to install Python 2.7 on CentOS.

tl;dr

yum groupinstall development
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
wget http://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 --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall

Solution

Python requires development tools to be installed first:

yum groupinstall development

If you are to use Python in any serious capacity, there are a number of extremely useful development modules that should be installed before Python, so the interpreter can recognize and load them during the installation.

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y

Download the required installer:

wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz

Uncompress the installer:

tar xf Python-2.7.6.tar.xz
cd Python-2.7.6

Finally, run the install:

./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall

This will take about 5-10 minutes, after which Python 2.7 will be ready to use on your system.


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 3428
Related articles: