Wednesday, 21 May 2014

Running Python 2.7 on RHEL6

I recently had to do some work on a RHEL6 environment, where the application I needed to test mandated python 2.7. Not a big ask...but RHEL6 is joined at the hip to python 2.6. so what to do...

There's a nice and easy way to use more 'up-to-date' versions of software platforms on RHEL without breaking the OS....

Software Collections

Software Collections provides a method for newer software platforms to co-exist with the versions that the OS relies upon. With a RHEL subscription, all you need to do is subscribe to the SCL channel, and you'll have access to all the new 'stuff'.

Here's how

rhn-channel --add --channel rhel-x86_64-server-6-rhscl-1
<enter your rhn credentials>

(if you're using CentOS - take a look at http://wiki.centos.org/AdditionalResources/Repositories/SCL for how you enable the repo)

Then go and grab the software with yum

yum install python27

This will establish a python2.7 environment under /opt/rh/root/python27

You can then check that all is well by
[root@my-host ~]# scl enable python27 'python -V'
Python 2.7.5


Now once you have the environment in place you can switch over to it, and install python packages through easy_install or pip as normal.
eg.

>scl enable python27 bash
>easy_install pip
>pip install <module>

Job done.

Now for the next bit. If you have a user that wants this environment everytime they login what do you do...getting them to issue the scl command is likely to provoke screams! So to keep them happy, get them to update their bash profile, to enable the scl whenever they start a shell.

Add the following to the user's .bash_profile 
. /opt/rh/python27/enable

Now when they login they'll automagically pickup the python 2.7 environment :)

And the beauty of the SCL, is the python environment used by the system is untouched

Simples.

No comments:

Post a Comment