Install a new version of the Python on CentOS without overwriting the system's python installation

** You have to decide where to install it based on your needs. Most popular place to go is /opt/.

1. Install epel (extra packages for enterprise linux). This will add the epel repo to yum and give us a running start at some normally unavailable packages. It also provides some updates to existing repo packages:

To install EPEL follow this link: http://b2ctran.wordpress.com/2013/03/08/enable-epel-repository-on-centos/

2. Preinstall dependencies: development tools, ssl and zlib and some other packages which will be needed by python
$ yum -y groupinstall 'Development Tools'
$ yum -y  install openssl-devel zlib zlib-devel
$ yum install -y gdbm-devel sqlite-devel tk-devel ncurses-devel bzip2-devel readline-devel db4-devel

3. Prepare python2.7 source code

$ cd
$ wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
$ tar –zvxf Python-2.7.2.tgz
$ cd Python-2.7.2

Configure the Modules/Setup.dist to enable the gzip and readline support by uncomment the associated entries.
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib –lz
#readline realine.c -lreadline –ltermcap

4. configure python so it will not overwriting the system’s default python
./configure –prefix= /opt/python2.7 --with-threads --enable-shared

1)--enable-shared is required if you are going to install mod_wsgi. Or you have to rebuild the python library.
2) However, if you choose –enable-shared parameter you may encounter error while you are trying to install pscopg2.

The error message is "ld cannot find lpython2.7".

Here is a solution to that:

$ cd /usr/lib64
$ sudo ln -s /opt/python2.7/lib/libpython2.7.so.1.0 libpython2.7.so.1.0
$ sudo ln -s libpython2.7.so.1.0 libpython2.7.so

5. make and install

$ make
$ sudo make install

6. Now we need to update BASH so that it knows about the new shared libraries that we have put on the system.

$ sudotouch /etc/ld.so.conf.d/opt-python2.7.conf
add put /opt/python2.7/lib in the created file
$ sudo /sbin/ldconfig

7. install setuptools and pip:

$wget https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
$sudo sh setuptools-0.6c11-py2.7.egg

if you encounter python2.7 could not found error, the following will probably fix it:
$ sudo ln -s /opt/python2.7/bin/python  /usr/bin/python2.7

After installing easy_install you can install pip: sudo /opt/python2.7/bin/easy_install pip

No comments:

Post a Comment

Datatable static image not found on the server

When you use ```datatables.min.css``` and ```datatables.min.js``` locally, instead of datatables CDN, you may have encountered that ```sort...