Ubuntu Gutsy - Django installation
Django is a commonly used framework when developing webapps.
Let's take a look at installing Django on an Ubuntu Gutsy Slice and look at integrating database support.
Prerequisites
Assuming you are using Apache, we need to install the correct mod:
sudo aptitude install libapache2-mod-python
Once done, we are ready to install the main Django package.
As with most packages, you can install them in one of two ways.
The first, and most common way to install Django, is from the Trunk (via subversion). This provides the latest features and bug fixes and is the recommended route:
Trunk
Let's go ahead and install via svn. Ensure you have subversion installed:
sudo aptitude install subversion
As with all sysadmin work, consistency is key. As such, create a 'sources' directory in your home folder and move into it:
mkdir /home/demo/sources
cd /home/demo/sources
Now we can check out the latest version:
svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk
Lastly, we need to create a couple of symlinks:
sudo ln -s /home/demo/sources/django-trunk/django /usr/lib/python2.5/site-packages/django
sudo ln -s /home/demo/sources/django-trunk/django/bin/django-admin.py /usr/local/bin/django-admin.py
Stable
The second installation method is via the Ubuntu package manager 'aptitude'.
This will install a known and stable version of Django but, of course, will be a slightly older version.
Let's try that now:
sudo aptitude install python-django
This method also takes care of any dependencies.
You can find the installed version like so:
django-admin --version
On my test slice that installed version 0.96.
Database
Now we can have a quick look at three databases (databii?) we can use with Django.
Namely, MySQL, Postgres and Sqlite.
MySQL
Installation of MySQL and the python bindings is simply:
sudo aptitude install mysql-server python-mysqldb
Note this will install exim4 as a dependency. If you would prefer something like Postfix, then do a post install:
sudo aptitude install postfix
This will remove exim4 and install postfix.
Postgres
Postgres and needed bindings are equally simple to install:
sudo aptitude install postgresql python-psycopg2
Note this won't install exim4 or postfix so you will need to install one of these should you have that requirement:
sudo aptitude install postfix
SQlite
This one is very simple as SQLite is automatically supported with Python 2.5.
Other Packages
Well, that's the base requirements for Django installed but there are a few other pacjages that you may find useful such as memcached and imaging utilities.
To install these, enter the following:
sudo aptitude install python-imaging python-docutils memcached
Done.
Summary
Although there are a couple of choices to make such as trunk vs stable and which database you prefer to use, installing Django is fairly simple.
BTW - thanks go to Jared (SuperJared) for the notes to enable this (and future) Django articles. Any mistakes are likely due to my interpretation of very clear and precise instructions :)
PickledOnion.


Article Comments:
Majd Taby commented Mon Jan 14 06:30:22 UTC 2008:
Hey, could you please add a section on how to access the setup? also, shouldn't you add the "python setup.py install" command at the end to actually "install" it?
anders commented Wed Jan 16 16:08:24 UTC 2008:
I second the above. I was able to setup using info from the Django documentation pages. However, I can't seem to get anything working... Also, do I need to add mod_python settings to httpd.conf? Any help appreciated.
omat commented Tue Feb 05 09:09:49 UTC 2008:
I think libjpeg, libpng, libgif, ... installation should also be mentioned here together with imaging installation.
DavidK commented Sun Mar 02 10:14:56 UTC 2008:
To install from the SVN method:
cd /home/demo/sources/django-trunk sudo python setup.py install
ynw commented Thu Mar 27 00:09:43 UTC 2008:
It would be nice to have an how to django on nginx
sofia commented Sat Apr 05 03:39:12 UTC 2008:
i second ynw
Trey Piepmeier commented Mon Apr 07 01:13:38 UTC 2008:
Some more information on next steps: http://www.inerciasensorial.com.br/2006/11/22/perils-of-software-development/django-on-slicehost-virtual-private-server/
Seanos commented Thu Jul 03 20:17:32 UTC 2008:
Majd Taby and DavidK - if you follow (all) the instructions given by PickledOnion there is no need to run 'setup.py install' as you will have symlinked the django folder to python's site-packages directory. To check it's installed just run 'python' and then 'import django', if you don't get any error it works.
This way you can run 'svn update' from the django-trunk directory to automatically update to the latest django revision.
Matt S commented Thu Jul 24 05:32:49 UTC 2008:
PickledOnion & Seanos are correct; sym-linking django/ into your site-packages/ directory on your PYTHON_PATH is all that is required.
Being able to
svn up ~/path/to/django-trunk/is a very handy thing - if you don't symlink, but do thepython setup.py installinstead, you can't update your install on the fly.As for articles: I'd like to see an Apache + Django on mod_wsgi article, as well as a nginx + Django on fcgi article.
Vulcan commented Tue Aug 05 15:06:26 UTC 2008:
django-admin.py is just django-admin under ubuntu due to a Debian policy guideline which says that: "When scripts are installed into a directory in the system PATH, the script name should not include an extension such as .sh or .pl that denotes the scripting language currently used to implement it. "
django-admin works fine without the symlink and without the ".py"
Zen Sand Garden commented Sat Dec 20 20:07:05 UTC 2008:
I wish they had a tool to just click to install Django. Can you guys make a tool like that.
Michael Grech commented Tue Feb 03 05:45:40 UTC 2009:
@Zen...are you serious? @vulcan...good call on the .py, had been developing ina different enviro for a while
zen commented Thu Mar 19 19:41:31 UTC 2009:
@Michael
Nah, I'm just tired of all the config choices. I'm a Python programmer, so naturally I hate when there's more than one best way to do it.
clark commented Wed Sep 23 01:46:53 UTC 2009:
Just install django and modpython on ubuntu 9.04, the tutorial works on 9.04 too. Most articles on the net prefers wsgi now, for me modpython is easier to setup, love it