Thursday, October 1, 2009

Installing python and django

python (not the snake :P) has been around for quite sometime. But lately after Google's announcement of App Engine I developed a growing interest in it. One major benefit of python is the code size. Compared to Java, the code size of python is considerable less. More of comparisons later, I will use this post to install python and django in a fresh linux box.

I start with a CentOS box with apache and yum installed.

Now for installing python

#yum install python

Normally mod_python would install, but if it is not installed already, run

#yum install mod_python
In Debian/Ubuntu it would be
#apt-get install libapache2-mod-python


To test python installation, run the command

# python

You should get something like
___________________________________
Python 2.4.3 (#1, Jan 21 2009, 01:10:13)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
____________________________________

Python has been successfully installed. Press Ctrl+D to exit the python shell.

django is not found in repository, so I would install from svn (subversion)
First install subversion

#yum install subversion

Now,

Change directory to /var/www
#cd /var/www

create a directory for django
#mkdir django-src
Change to the django directory
#cd django-src
Download django from svn
#svn co http://code.djangoproject.com/svn/django/trunk/
django source would be downloaded into a sub-folder trunk. Change to the trunk folder
#cd trunk
install django
#python setup.py install

For debian and ubuntu it is a single command
#apt-get install python-django python-mysqldb


Install and start mysql server

#yum install mysql-server
#/etc/init.d/mysqld start


Now to install MySQL-python
(Normally mysql-python installed with yum is an old version, to install the latest follow this)

Installing the necessary tools
#yum install python-devel mysql-devel gcc
Download MySQL-python from http://sourceforge.net/project/showfiles.php?group_id=22307
Extract the compressed file
#tar zxvf <filename of MySQLdb tarball>
Change to the extracted folder
#cd <name of newly created directory by the tar command>
Build and Install from the MySQL-python source
#python setup.py build
#python setup.py install


MySQL-python is installed as .egg file in your site-packages directory.

To run your django application
#python manage.py runserver 127.0.0.1:8000


To additionally install Python Imaging Library
#yum install python-imaging

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.