I recently was installing Django for a test project and needed to upgrade Python on a CentOS server to 2.6. The current revisions available via yum on CentOS are 2.4. The yum package manager requires Python 2.4 still to function properly so upgrading Python to 2.6 manually will break the CentOS yum package manager. After a little bit of research I found a yum repository that would allow you to install Python version 2.6 in parallel to Python version 2.4. Below I explain how to install the new Python version, not break the yum package manager, and modify a Django project that references Python to use the 2.6 version instead of the 2.4 version.
**UPDATE** When I initially wrote this article the server I installed the CHL repository on already had the EPEL repository installed. You can read this article on installing the EPEL repository. Thanks to Tom for noting the EPEL repository is required in the comments section of this article.
Install CHL Yum Repo That Provides Python 2.6 On CentOS 5:
First I want to say thanks to Chris Lea for providing the yum repository that makes this whole process easy. The below to commands will install a yum repository and the required GPG key for the repo.
Use The RPM Command To Install The CHL Yum Repo And CHL Yum RPM GPG Key:
- rpm -Uvh http://yum.chrislea.com/centos/5/i386/chl-release-5-3.noarch.rpm
- rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CHL
The above will install the CHL yum repository by adding chl.repo to the /etc/yum.repos.d directory. It will add the ability to search yum.chrislea.com to your current list of repositories. The Python packages available via CHL are titled python26-* instead of python-*. This allows you to install a completely separate version of Python and run both on your system. You will leave the current version of Python how it is so the other packages on the server that require python don’t break.
Now Install Python Version 2.6, Mod_Python (v2.6), Django, And MySQL-Python (v2.60):
The below command will install Python 2.6 and supporting packages that allow Django to run on a server using Apache, MySQL, and Python. Notice the “26” on the end of each package that will literally install the 2.6 version of each one.
Install python26, mod_python26, django, & mysql-python26 on CentOS:
- yum install python26 mod_python26 Django MySQL-python26
Once installed you will now have the ability to run Python version 2.6 by issuing the python26 from the command line. The above packages will also allow interaction with Apache and MySQL so a fully functional dynamic Django site can now be configured.
Modify Django Environment Variables To Use Python 2.6:
One other thing you will need to modify is the default Django project files you will eventually install. The files will specify at the top of them that the code below is Python. You will want to modify that configuration line and make sure that it references python26 instead so the application knows to process the code using the 2.6 version of Python.
Default Python Application Environment Specification:
- #!/usr/bin/env python
Modified Python Application Environment Specification:
- #!/usr/bin/env python26
So search through the Django project and check for any files with the default Python specification. Modify that default to the modified one that tells the Django project to use Python version 2.6.
Important to read the readme.txt
“It expects that you already have the EPEL repository set up
and working. You can get my repo in by doing”
If you don’t have the EPEL repository set up these packages won’t install
http://yum.chrislea.com/readme.txt
Hello Tom,
Thanks for adding this. I wasn’t aware about the EPEL repo and must have had it set up already on this server when I installed the new repo.
Anyway thanks for adding this for others…
Thanks.
alex
Thanks for the nice instructions, worked like a charm after that, except I had a conflict for mod_python26, but wasn’t much of an issue since I prefer mod_wsgi and followed the instructions here to compile it.
http://www.webtop.com.au/installing-wsgi-adaptor-for-apache-using-mod-wsgi
Thanks again,
Tom
Hello Tom,
No problem at all. Thanks again for responding with more info so others can use mod_wsgi if they want. I personally ended up not using mod_python either and switched to running what I was working with out of mod_fastcgi which has worked great so far.
Thanks!
alex
Hi,
Thanks for your how to.
Unfortunately, I am running x64 (Read Hat AS 5), and I have missing libs dependency:
Error: Missing Dependency: libbz2.so.1 is needed by package python26
Error: Missing Dependency: libgdbm.so.2 is needed by package python26
I’ll post once solved.
Fred
Ok, here are the missing packages that did it:
apt-get install bzip2-libs.32bit
apt-get install gdbm.32bit
Fred
Hello Fred,
Thanks for posting this. I am sure it will help others in the future. As I mentioned in my initial response I will be posting an article soon. Please keep in mind that the Python version installed from this article is Python 2.6 i386. The new article I will be posting will discuss installing the Python version 2.6 x86_64 package using a different repository. I ran into an issue where I needed Python 2.6 x86_64 to compile something on a 64-bit CentOS server.
Thanks.
alex
Hi Alex
Did you ever get round to writing the article ?
As I’m trying to install python 2.6 on cents 5 x86_64.
Thanks
Hello Jovan,
Unfortunately I did not and don’t have any spare time at the moment to do so.
Sorry…
Thanks.
alex
Hello Fred,
No problem. Thanks for taking the time to post. I actually have an article I will be writing soon regarding Python version 2.6 and 64-bit CentOS Linux 5.X which would apply the same way to Red Hat AS 5.
Thanks.
alex
For a novice users like me: what about installing python modules in the case described in your article? should I “python setup.py install” or “python26 setup.py install”?
Hello Roman,
If you use python setup.py install it will install it for python 2.4 and python26 setup.py install will do so for python 2.6. You should see if there are yum packages in the repo mentioned in the article though for best results.
Thanks.
alex
When you install Django using this method where are the project files installed? I can’t seem to find any installation of Django.
Hello Brad,
I don’t recall specifically as its been quite awhile but using the above method did allow me to use Django without issue. Just run “updatedb” and then use locate to find whatever file/files you are looking for.
Thanks.
alex
In the python README it discusses running multiple versions. Here’s what I did.
./configure –prefix /usr (this was so python2.6 would install in the same location as python2.4, just my preference)
make
make altinstall
This SEEMS to work. yum still functions. I used it to upgrade my 2.4.3 to 2.4.3-27
Take it for what it’s worth, I’m still quite new to Linux.
Hello Ed,
Cool. Thanks for the tip. I wasn’t aware you could do it this way. While I personally still prefer doing it via a package manager this is not only something I am glad to know but something others will find useful. Thanks again for taking the time to share.
Linux rocks! The beauty of it is there are a thousand roads that lead to similar solutions and the fact that the community not only shares but does so willingly.
Thanks.
alex
No package MySQL-python26 available.
:(
Hello Robert,
Did you follow the instructions and install the new YUM repo? If you are on a 64-bit machine you may need to specify the package as i386. Make sure the new YUM repo is installed as well.
Thanks.
alex
Hey Alex,
Im also getting no packages found. The repo is installed, and I can see it. When I yum update, it see`s the repo, but cant find any package. Here is a ls of my repo dir and what happens when I try install python26:
root@nerthus [/etc/yum.repos.d]# ls
./ ../ CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo chl.repo mirrors-rpmforge rpmforge.repo rpmforge-testing.repo
root@nerthus [/etc/yum.repos.d]# yum install python26
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.finalasp.com
* extras: mirror.raystedman.net
* updates: mirrors.tummy.com
Excluding Packages in global exclude list
Finished
Setting up Install Process
No package python26 available.
Nothing to do
root@nerthus [/etc/yum.repos.d]#
It is a 64bit system so how do I specify the package as 386 as you mentioned to get it working? Thanks for the help!
Hello Dave,
Instead of something like the below…
yum install python25
You would instead use something like the below which specifies i386 or 32bit versus x86-64 or 64bit.
yum install python25.i386
Hope that helps…
Thanks.
alex