Ubuntu Hardy - Django Installation

This series of articles will take you through the installation and deployment of a Django based web application. This article in particular will serve to get Django installed and be a base for the rest of the articles in the series.


Prerequisites

So, you've gone through and completed these articles Ubuntu Hardy setup page 1 and Ubuntu Hardy setup page 2 and now you want to start a Django project? If you have not completed the steps outlined in those articles, please make sure you do before going on with this article!

Okay, moving right along, assuming you've followed the first two articles, let's get started and install subversion so we can grab the latest version of Django code.

First we'll need to log into our slice:

ssh -p30000 demo@123.234.137.216

Obviously remember to replace 30000 with the port number you selected in Hardy Setup 1, demo with your username and the IP with your slice IP.

Once you're logged in, let's go ahead and grab subversion (two install methods do not use subversion, but the method I will choose does use subversion). Use the following command to install subversion:

sudo aptitude install subversion

Hit enter and watch the magic happen.

By default Django will use sqlite as its datastore but it can use other databases as well (PostgreSQL, MySQL, etc.), depending on your database of choice you may want to install the appropriate packages. This article, however, will not get into using a database at all; instead there will be separate articles for a few different database systems.

Optional Installs

There are a few packages you may wish to install at this point that are pretty commonly used with Django. To install the optional packages use this command:

sudo aptitude install python-imaging python-pythonmagick python-markdown python-textile python-docutils

You can use the show subcommand in aptitude with a given package name to show you more information about the package:

aptitude show python-imaging

You can examine the optional packages listed above and decide if you'll want to be using them, again they're not required but they are used frequently.

Django Download/Installation

Now that we have all of our packages, let's get the latest version of Django...

The aptitude Way (not currently recommended)

As of this writing, v0.96 is the latest version available from aptitude. This, however, is actually quite old as the official 1.0 stable version was released in September of 2008 so I would recommend one of the next two installation options since I'll be using the 1.0+ version of Django for the rest of the articles. Nevertheless, if you want to play it really safe this is what aptitude gave us to work with, so let's have at it:

sudo aptitude install python-django

That's it. Django should now be installed and useable. To make sure it got installed, run the following command:

django-admin

It should respond with:

Type 'django-admin help' for usage.

Skip down to "Next Steps."

The stable non-aptitude Way

If running the old version available in aptitude isn't your cup-of-tea but neither is the bleeding edge svn method (demonstrated below) this method will be your best bet. We're going to download the package for the official 1.0 stable release and install it manually. Fire up wget and follow these steps:

wget http://www.djangoproject.com/download/1.0.2/tarball/
tar xzvf Django-1.0.2-final.tar.gz
cd Django-1.0.2-final
sudo python setup.py install

That should be it, the latest and greatest stable version of Django should now be installed and ready for use. Do note that 1.0.2 is the latest as of this update. Always check the site for the latest stable version.

To make sure it got installed, run the following command:

django-admin.py

It should respond with:

Type 'django-admin.py help' for usage.

Skip down to "Next Steps."

The Subversion Way

If you're all about having the latest and greatest code even if that might mean it's got some quirks every now and again, grabbing the code from the Django subversion repository will give us just that. The Django guys claim to keep their trunk checkins pretty stable, so you may not experience any issues with this method, but it is a possibility. This is the method I will use (and assume in later articles). If you use one of the other methods, please be aware that the older version may be lacking some features.

mkdir /home/demo/sources
cd /home/demo/sources
svn co http://code.djangoproject.com/svn/django/trunk/django django

Now prepare to watch several lines of text roll up your screen. Maybe get a cup of Coffee or Tea, this will take a minute.

For this next step, we'll need to know the python site-packages path. If you know it off hand, great! If not, simply run this command to find out:

python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

It should spit out:

/usr/lib/python2.5/site-packages

Now we can setup a couple of links to our Django installation. If you've managed to navigate away from your sources directory, please navigate back there:

cd /home/demo/sources

and then let's run the following commands to setup our symbolic links:

sudo ln -s /home/demo/sources/django /usr/lib/python2.5/site-packages/django
sudo ln -s /home/demo/sources/django/bin/django-admin.py /usr/local/bin/django-admin.py

To make sure it got installed, run the following command:

django-admin.py

It should respond with:

Type 'django-admin.py help' for usage.

Skip down to "Next Steps."

Next Steps

Now we're ready to move on to installing a web server to actually serve a Django application. There are a couple methods for doing this, the two I will cover will be mod_python and mod_wsgi.

Ben H.

Article Comments:

Tyler commented Mon Dec 22 20:18:18 UTC 2008:

I'm really looking forward to the next few articles. Thanks!

Steve Cox commented Fri Jan 02 21:21:52 UTC 2009:

I'm also looking forward to the next articles. All of these tutorials are fantastic

Steve

Nathaniel Varona commented Sun Feb 01 16:12:23 UTC 2009:

I like it... install django without apt-get repository...

Kevin Chiu commented Mon Feb 02 22:26:29 UTC 2009:

If we can't wait for the next article(s), do you have a suggestion for where we could get the info we need to set up a django production environment?

David Nichols commented Mon Apr 06 00:32:07 UTC 2009:

A good little article, this one! I'm very much looking forward to the follow-ups. Thanks

conficker commented Mon Apr 06 22:54:14 UTC 2009:

Is Hardy Ubuntu the best setup for production applications?

Regi E. commented Sun Jun 21 05:44:13 UTC 2009:

This should be changed to "/usr/lib/python2.6/dist-packages/django" if you have python2.6 on your system.

"site-packages" -> "dist-packages"

Ronald Affee commented Mon Jan 25 02:01:56 UTC 2010:

I've been finding a lot of great articles out there. Thanks for the post.

Orlando Advertising Agency commented Mon Jan 25 02:07:39 UTC 2010:

Please keep uploading articles.

Aaron commented Mon Mar 15 23:41:25 UTC 2010:

pyPkgPath=python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

echo $pyPkgPath # optional

ln -s /home/demo/sources/django $pyPkgPath/django

Aaron commented Mon Mar 15 23:46:34 UTC 2010:

Try that again:

pyPkgPath=`python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"`

echo $pyPkgPath # optional

ln -s /home/demo/sources/django $pyPkgPath/django

Jeff Yamada commented Sat May 07 01:39:38 UTC 2011:

Great help! Thanks!

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)