More on installing Django

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_psycopg2 package. 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-python package, 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 cx_Oracle.
  • 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 migrate command 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 SELECT, INSERT, UPDATE and DELETE permissions. After creating a database user with these permissions, you’ll specify the details in your project’s settings file, see DATABASES for details.

If you’re using Django’s testing framework to test database queries, Django will need permission to create a test database.

Installing Django Manually

  1. Download the latest release from the Django Project download page.
  2. Untar the downloaded file (e.g. tar xzvf Django-X.Y.tar.gz, where X.Y is the version number of the latest release). If you’re using Windows, you can download the command-line tool bsdtar to do this, or you can use a GUI-based tool such as 7-zip.
  3. Change into the directory created in step 2 (e.g. cd Django-X.Y).
  4. If you’re using Linux, Mac OS X or some other flavor of Unix, enter the command sudo python install at the shell prompt. If you’re using Windows, start a command shell with administrator privileges and run the command python install. This will install Django in your Python installation’s site-packages directory.

Upgrading Django

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 pip or easy_install previously, installing with pip or 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):

python -c "import sys; sys.path = sys.path[1:]; import django; print(django.__path__)"

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:

  1. Make sure that you have Git installed and that you can run its commands from a shell. (Enter git help at a shell prompt to test this.)
  2. Check out Django’s main development branch (the ‘trunk’ or ‘master’) like so:
     git clone git:// django-trunk

    This will create a directory django-trunk in your current directory.

  3. 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:
     sudo pip install -e django-trunk/

(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!

What’s Next?

In the next chapter we will be covering addition information specific to running Django with particular databases.