Wednesday 18 February 2009

Python2.5 on SLC4

So, a recurring problem when writing django apps, or using django tools is that then often use features only on python2.4 or python2.4 (properties, with: clauses, ...).

Here's a recipe to get python2.5 onto a SLC4 system without causing too much pain. Again it uses pip and virtualenv to do the heavy lifting.

First, install python2.5 - the ATLAS rpms in AFS seem the easiest place (but it's built by the SLC maintainers, so should be available someone more standard too !)
# rpm -Uvh /afs/cern.ch/atlas/offline/external/GRID/ddm/ext/RPMS.py25.x86_64/python25-2.5.2-2.slc4.x86_64.rpm
# which python2.5
/usr/bin/python2.5
# python2.5
Python 2.5.2 (r252:60911, Apr 28 2008, 11:39:35)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

So now we've got python2.5, let's get virtualenv and pip running. First, get easy_install:
# wget http://peak.telecommunity.com/dist/ez_setup.py
--11:40:46-- http://peak.telecommunity.com/dist/ez_setup.py
=> `ez_setup.py'
Resolving peak.telecommunity.com... 209.190.5.234
Connecting to peak.telecommunity.com|209.190.5.234|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9,716 (9.5K) [text/plain]

100%[=========================================================================================================>] 9,716 39.37K/s

11:40:47 (39.34 KB/s) - `ez_setup.py' saved [9716/9716]
# python2.5 ez_setup.py --install-dir /usr/lib64/python2.5/site-packages/
Downloading http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c9-py2.5.egg
Processing setuptools-0.6c9-py2.5.egg
Copying setuptools-0.6c9-py2.5.egg to /usr/lib64/python2.5/site-packages
Adding setuptools 0.6c9 to easy-install.pth file
Installing easy_install script to /usr/lib64/python2.5/site-packages/
Installing easy_install-2.5 script to /usr/lib64/python2.5/site-packages/

Installed /usr/lib64/python2.5/site-packages/setuptools-0.6c9-py2.5.egg
Processing dependencies for setuptools==0.6c9
Finished processing dependencies for setuptools==0.6c9

# python2.5 /usr/lib64/python2.5/site-packages/easy_install --install-dir /usr/lib64/python2.5/site-packages/ --script-dir /usr/bin pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Reading http://pip.openplans.org
Best match: pip 0.3.1
Downloading http://pypi.python.org/packages/source/p/pip/pip-0.3.1.tar.gz#md5=78102ddbb040a183dd361b5d432cdf88
Processing pip-0.3.1.tar.gz
Running pip-0.3.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-TwXZ62/pip-0.3.1/egg-dist-tmp-UPf9BM
warning: manifest_maker: MANIFEST.in, line 3: 'prune' expects a single
warning: manifest_maker: MANIFEST.in, line 4: 'prune' expects a single
warning: manifest_maker: MANIFEST.in, line 5: 'prune' expects a single
zip_safe flag not set; analyzing archive contents...
pip: module references __file__
Adding pip 0.3.1 to easy-install.pth file
Installing pip script to /usr/bin

Installed /usr/lib64/python2.5/site-packages/pip-0.3.1-py2.5.egg
Processing dependencies for pip
Finished processing dependencies for pip

# python2.5 /usr/lib64/python2.5/site-packages/easy_install --install-dir /usr/lib64/python2.5/site-packages/ --script-dir /usr/bin virtualenv
Searching for virtualenv
Reading http://pypi.python.org/simple/virtualenv/
Best match: virtualenv 1.3.2
Downloading http://pypi.python.org/packages/2.5/v/virtualenv/virtualenv-1.3.2-py2.5.egg#md5=f2cd2b10b8be8b57e74cb1830fc0b504
Processing virtualenv-1.3.2-py2.5.egg
creating /usr/lib64/python2.5/site-packages/virtualenv-1.3.2-py2.5.egg
Extracting virtualenv-1.3.2-py2.5.egg to /usr/lib64/python2.5/site-packages
Adding virtualenv 1.3.2 to easy-install.pth file
Installing virtualenv script to /usr/bin

Installed /usr/lib64/python2.5/site-packages/virtualenv-1.3.2-py2.5.egg
Processing dependencies for virtualenv
Finished processing dependencies for virtualenv

Note the path hacking we had to do to get things all in the right place - EasyInstall doesn't seem to expect site-packages to be in /usr/lib64 on x86_64. Now you've got this going, you can just go ahead and create virtualenv's. Since the /bin/virtualenv and /bin/pip use python2.5, there's not even any need to supply the '-p' option to virtualenv to specify the python to use - it'll default to 2.5.
# pip -E /tmp/devo install Django
Creating new virtualenv environment in /tmp/devo
New python executable in /tmp/devo/bin/python2.5
Also creating executable in /tmp/devo/bin/python
Installing setuptools...done.....
Downloading/unpacking Django
Downloading Django-1.0.2-final.tar.gz (4.6Mb): 4.6Mb downloaded
Running setup.py egg_info for package Django
Installing collected packages: Django
Running setup.py install for Django
changing mode of build/scripts-2.5/django-admin.py from 644 to 755
changing mode of /tmp/devo/bin/django-admin.py to 755
Successfully installed Django

# source /tmp/devo/bin/activate
(devo)[root@lxbra1905 ~]# python
Python 2.5.2 (r252:60911, Apr 28 2008, 11:39:35)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
/>>> import django
/>>>





No comments: