This chapter covers some of the more common additional options and scenarios associated with installing and maintaining Django. Firstly, we will look at installation configurations for using databases other than SQLite and then we will cover how to upgrade Django as well as how you can manually install Django. Finally, we will cover how to install the development version of Django just in case you want to play with the bleeding edge of Django development.
Running Other Databases
If you plan to use Django’s database API functionality, you’ll need to make sure a database server is running. Django supports many different database servers and is officially supported with PostgreSQL, MySQL, Oracle and SQLite.
Chapter 21 contains additional information specific to connecting Django to each of these databases, however it’s beyond the scope of this book to show you how to install them; please refer to the database documentation at each projects’ website.
If you are developing a simple project or something you don’t plan to deploy in a production environment, SQLite is generally the simplest option as it doesn’t require running a separate server.
However, SQLite has many differences from other databases, so if you are working on something substantial, it’s recommended to develop with the same database as you plan on using in production.
In addition to a database backend, you’ll need to make sure your Python database bindings are installed.
- If you’re using PostgreSQL, you’ll need the
postgresql_psycopg2package. You might want to refer to the PostgreSQL notes for further technical details specific to this database. If you’re on Windows,
check out the unofficial compiled Windows version.
- If you’re using MySQL, you’ll need the
MySQL-pythonpackage, version 1.2.1p2 or higher. You will also want to read the database-specific notes for the MySQL backend.
- If you’re using SQLite, you might want to read the SQLite backend notes.
- If you’re using Oracle, you’ll need a copy of
cx_Oracle, but please read the database-specific notes for the Oracle backend for important information regarding supported versions of both Oracle and
- If you’re using an unofficial 3rd party backend, please consult the documentation provided for any additional requirements.
If you plan to use Django’s
manage.py migratecommand to automatically create database tables for your models (after first installing Django and creating a project), you’ll need to ensure that Django has permission to create and alter tables in the database you’re using; if you plan to manually create the tables, you can simply grant Django
DELETEpermissions. After creating a database user with these permissions, you’ll specify the details in your project’s settings file, see
If you’re using Django’s testing framework to test database queries, Django will need permission to create a test database.
Installing Django Manually
- Download the latest release from the Django Project download page.
- Untar the downloaded file (e.g.
tar xzvf Django-X.Y.tar.gz, where
X.Yis the version number of the latest release). If you’re using Windows, you can download the command-line tool
bsdtarto do this, or you can use a GUI-based tool such as 7-zip.
- Change into the directory created in step 2 (e.g.
- If you’re using Linux, Mac OS X or some other flavor of Unix, enter the command
sudo python setup.py installat the shell prompt. If you’re using Windows, start a command shell with administrator privileges and run the command
python setup.py install. This will install Django in your Python installation’s
Remove Any Old Versions of Django
If you are upgrading your installation of Django from a previous version, you will need to uninstall the old Django version before installing the new version.
If you installed Django using
easy_install previously, installing with
easy_install again will automatically take care of the old version, so you don’t need to do it yourself.
If you previously installed Django manually, uninstalling is as simple as deleting the
django directory from your Python
site-packages. To find the directory you need to remove, you can run the following at your shell prompt (not the interactive Python prompt):
Installing A Distribution-Specific Package
Check the distribution specific notes to see if your platform/distribution provides official Django packages/installers. Distribution-provided packages will typically allow for automatic installation of dependencies and easy upgrade paths; however, these packages will rarely contain the latest release of Django.
Installing The Development Version
If you decide to use the latest development version of Django, you’ll want to pay close attention to the development timeline, and you’ll want to keep an eye on the release notes for the upcoming release. This will help you stay on top of any new features you might want to use, as well as any changes you’ll need to make to your code when updating your copy of Django. (For stable releases, any necessary changes are documented in the release notes.)
If you’d like to be able to update your Django code occasionally with the latest bug fixes and improvements, follow these instructions:
- Make sure that you have Git installed and that you can run its commands from a shell. (Enter
git helpat a shell prompt to test this.)
- Check out Django’s main development branch (the ‘trunk’ or ‘master’) like so:
This will create a directory
django-trunkin your current directory.
- Make sure that the Python interpreter can load Django’s code. The most convenient way to do this is via pip. Run the following command:
(If using a virtualenv, or running Windows, you can omit
sudo.) This will make Django’s code importable, and will also make the
django-admin utility command available. In other words, you’re all set!
In the next chapter we will be covering addition information specific to running Django with particular databases.