Though Django support python2.4 bundled with this OS, I decide to get it running on Python2.6, which makes me feel not so out. In the beginning I was thinking it could be a task of 10 mins, and not expecting so many unexpected things happened:
The first issue is replacing python2.4 with python2.6 breaks the yum toolkit on CentOS 5.2. Shame for that. Fortunately some other guys has met the problem already and there are lot's of blogs and question/answers addressing this issue. I follow this one: how to install python2.6 on centos5 without breaking yum. It almost works, just a minor problem: yum report that libffi-3.0 not found while installing python2.6. So google again, and there it is:
After installing this rpm package, I can get python2.6 installed.
Now download Django-1.2.3.tar.gz from official site, unpack, and run
python26 setup.py install. Oops, wait, there is problem:
invalid Python installation: unable to open usr/lib/python2.6/config/Makefile
Okay, google again, and someone said it's due to you have not installed python-dev package. Let's try
yum install python26-devand then run
python26 setup.py installagain. Bingo!
Now that we have the Django installed at
/usr/lib/python2.6/site-packages. Let's give it a try:
/etc/bashrc, add "
. /etc/bashrc && chmod a+x $DJANGO_HOME/bin/*.py
ln -s $DJANGO_HOME/bin/django-admin.py /usr/bin/django-admin.py
django-admin startproject mysite
Oops, error again:
Traceback (most recent call last):
File "/usr/bin/django-admin.py", line 2, in ?
from django.core import management
ImportError: No module named django.core
Damn it, I forgot django is installed to python26. Okay, let me do something to hack it:
# cd $DJANGO_HOME/bin
# find . -name '*.py' | sed -i 's/env python/env python26/'
django-admin startproject mysiteworks. and let me continue:
cd mysite && python26 manage.py runserver
OMG, it breaks again, all the files generated by
django-adminuse python as default env, not python26. I am getting tired of adding my hacks to Django. I need to figure out some other ways.
Yes, python support virtualenv, that's exactly what I need! Follow the process described in this blog, I can continue again:
# wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.5.1.tar.gz
# tar xzf virtualenv-1.5.1.tar.gz
# cd virtualenv-1.5.1
# su greenl
$ python26 virtualenv.py ~/opt/local
$ cd ~
$ wget http://www.doughellmann.com/downloads/virtualenvwrapper-1.23.tar.gz
$ tar xzf virtualenvwrapper-1.23.tar.gz
$ cd virtualenvwrapper-1.23
$ cp virtualenvwrapper_bashrc ~/bin
$ cd ~
$ mkdir .virtualenvs
$ mkvirtualenv django
$ workon django
$ easy_install django
$ cd /tmp
$ sudo rm -rf mysite
$ django-admin.py startproject mysite
$ cd mysite
$ python manage.py runserver &
$ lynx localhost:8000
1. You can install python2.6 on CentOS 5 without breaking yum
2. You can install django latest version (currently v1.2.3) on python2.6 site-packages
3. You need to install virtualenv in order to get django run on python2.6 transparently
4. You may want to install virtualenvwrapper in order to make your life easier with virtualenv.
5. After you have done all these, you have an nice env for your django journey!