|
1 ===================== |
|
2 How to install Django |
|
3 ===================== |
|
4 |
|
5 This document will get you up and running with Django. |
|
6 |
|
7 Install Python |
|
8 ============== |
|
9 |
|
10 Being a Python Web framework, Django requires Python. |
|
11 |
|
12 It works with any Python version from 2.4 to 2.7 (due to backwards |
|
13 incompatibilities in Python 3.0, Django does not currently work with |
|
14 Python 3.0; see :doc:`the Django FAQ </faq/install>` for more |
|
15 information on supported Python versions and the 3.0 transition). |
|
16 |
|
17 Get Python at http://www.python.org. If you're running Linux or Mac OS X, you |
|
18 probably already have it installed. |
|
19 |
|
20 .. admonition:: Django on Jython |
|
21 |
|
22 If you use Jython_ (a Python implementation for the Java platform), you'll |
|
23 need to follow a few additional steps. See :doc:`/howto/jython` for details. |
|
24 |
|
25 .. _jython: http://jython.org/ |
|
26 |
|
27 Install Apache and mod_wsgi |
|
28 ============================= |
|
29 |
|
30 If you just want to experiment with Django, skip ahead to the next section; |
|
31 Django includes a lightweight Web server you can use for testing, so you won't |
|
32 need to set up Apache until you're ready to deploy Django in production. |
|
33 |
|
34 If you want to use Django on a production site, use Apache with `mod_wsgi`_. |
|
35 mod_wsgi is similar to mod_perl -- it embeds Python within Apache and loads |
|
36 Python code into memory when the server starts. Code stays in memory throughout |
|
37 the life of an Apache process, which leads to significant performance gains over |
|
38 other server arrangements. Make sure you have Apache installed, with the |
|
39 mod_wsgi module activated. Django will work with any version of Apache that |
|
40 supports mod_wsgi. |
|
41 |
|
42 See :doc:`How to use Django with mod_wsgi </howto/deployment/modwsgi>` for |
|
43 information on how to configure mod_wsgi once you have it installed. |
|
44 |
|
45 If you can't use mod_wsgi for some reason, fear not: Django supports many other |
|
46 deployment options. A great second choice is :doc:`mod_python |
|
47 </howto/deployment/modpython>`, the predecessor to mod_wsgi. Additionally, Django |
|
48 follows the WSGI_ spec, which allows it to run on a variety of server platforms. |
|
49 See the `server-arrangements wiki page`_ for specific installation instructions |
|
50 for each platform. |
|
51 |
|
52 .. _Apache: http://httpd.apache.org/ |
|
53 .. _mod_wsgi: http://code.google.com/p/modwsgi/ |
|
54 .. _WSGI: http://www.python.org/dev/peps/pep-0333/ |
|
55 .. _server-arrangements wiki page: http://code.djangoproject.com/wiki/ServerArrangements |
|
56 |
|
57 .. _database-installation: |
|
58 |
|
59 Get your database running |
|
60 ========================= |
|
61 |
|
62 If you plan to use Django's database API functionality, you'll need to make |
|
63 sure a database server is running. Django supports many different database |
|
64 servers and is officially supported with PostgreSQL_, MySQL_, Oracle_ and |
|
65 SQLite_ (although SQLite doesn't require a separate server to be running). |
|
66 |
|
67 In addition to the officially supported databases, there are backends provided |
|
68 by 3rd parties that allow you to use other databases with Django: |
|
69 |
|
70 * `Sybase SQL Anywhere`_ |
|
71 * `IBM DB2`_ |
|
72 * `Microsoft SQL Server 2005`_ |
|
73 * Firebird_ |
|
74 * ODBC_ |
|
75 |
|
76 The Django versions and ORM features supported by these unofficial backends |
|
77 vary considerably. Queries regarding the specific capabilities of these |
|
78 unofficial backends, along with any support queries, should be directed to the |
|
79 support channels provided by each 3rd party project. |
|
80 |
|
81 In addition to a database backend, you'll need to make sure your Python |
|
82 database bindings are installed. |
|
83 |
|
84 * If you're using PostgreSQL, you'll need the psycopg_ package. Django supports |
|
85 both version 1 and 2. (When you configure Django's database layer, specify |
|
86 either ``postgresql`` [for version 1] or ``postgresql_psycopg2`` [for version 2].) |
|
87 You might want to refer to our :ref:`PostgreSQL notes <postgresql-notes>` for |
|
88 further technical details specific to this database. |
|
89 |
|
90 If you're on Windows, check out the unofficial `compiled Windows version`_. |
|
91 |
|
92 * If you're using MySQL, you'll need MySQLdb_, version 1.2.1p2 or higher. You |
|
93 will also want to read the database-specific :ref:`notes for the MySQL |
|
94 backend <mysql-notes>`. |
|
95 |
|
96 * If you're using SQLite and Python 2.4, you'll need pysqlite_. Use version |
|
97 2.0.3 or higher. Python 2.5 ships with an SQLite wrapper in the standard |
|
98 library, so you don't need to install anything extra in that case. Please |
|
99 read the :ref:`SQLite backend notes <sqlite-notes>`. |
|
100 |
|
101 * If you're using Oracle, you'll need a copy of cx_Oracle_, but please |
|
102 read the database-specific :ref:`notes for the Oracle backend <oracle-notes>` |
|
103 for important information regarding supported versions of both Oracle and |
|
104 ``cx_Oracle``. |
|
105 |
|
106 * If you're using an unofficial 3rd party backend, please consult the |
|
107 documentation provided for any additional requirements. |
|
108 |
|
109 If you plan to use Django's ``manage.py syncdb`` command to |
|
110 automatically create database tables for your models, you'll need to |
|
111 ensure that Django has permission to create and alter tables in the |
|
112 database you're using; if you plan to manually create the tables, you |
|
113 can simply grant Django ``SELECT``, ``INSERT``, ``UPDATE`` and |
|
114 ``DELETE`` permissions. On some databases, Django will need |
|
115 ``ALTER TABLE`` privileges during ``syncdb`` but won't issue |
|
116 ``ALTER TABLE`` statements on a table once ``syncdb`` has created it. |
|
117 |
|
118 If you're using Django's :doc:`testing framework</topics/testing>` to test database queries, |
|
119 Django will need permission to create a test database. |
|
120 |
|
121 .. _PostgreSQL: http://www.postgresql.org/ |
|
122 .. _MySQL: http://www.mysql.com/ |
|
123 .. _psycopg: http://initd.org/pub/software/psycopg/ |
|
124 .. _compiled Windows version: http://stickpeople.com/projects/python/win-psycopg/ |
|
125 .. _MySQLdb: http://sourceforge.net/projects/mysql-python |
|
126 .. _SQLite: http://www.sqlite.org/ |
|
127 .. _pysqlite: http://trac.edgewall.org/wiki/PySqlite |
|
128 .. _cx_Oracle: http://cx-oracle.sourceforge.net/ |
|
129 .. _Oracle: http://www.oracle.com/ |
|
130 .. _Sybase SQL Anywhere: http://code.google.com/p/sqlany-django/ |
|
131 .. _IBM DB2: http://code.google.com/p/ibm-db/ |
|
132 .. _Microsoft SQL Server 2005: http://code.google.com/p/django-mssql/ |
|
133 .. _Firebird: http://code.google.com/p/django-firebird/ |
|
134 .. _ODBC: http://code.google.com/p/django-pyodbc/ |
|
135 .. _removing-old-versions-of-django: |
|
136 |
|
137 Remove any old versions of Django |
|
138 ================================= |
|
139 |
|
140 If you are upgrading your installation of Django from a previous version, |
|
141 you will need to uninstall the old Django version before installing the |
|
142 new version. |
|
143 |
|
144 If you installed Django using ``setup.py install``, uninstalling |
|
145 is as simple as deleting the ``django`` directory from your Python |
|
146 ``site-packages``. |
|
147 |
|
148 If you installed Django from a Python egg, remove the Django ``.egg`` file, |
|
149 and remove the reference to the egg in the file named ``easy-install.pth``. |
|
150 This file should also be located in your ``site-packages`` directory. |
|
151 |
|
152 .. admonition:: Where are my ``site-packages`` stored? |
|
153 |
|
154 The location of the ``site-packages`` directory depends on the operating |
|
155 system, and the location in which Python was installed. To find out your |
|
156 system's ``site-packages`` location, execute the following: |
|
157 |
|
158 .. code-block:: bash |
|
159 |
|
160 python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" |
|
161 |
|
162 (Note that this should be run from a shell prompt, not a Python interactive |
|
163 prompt.) |
|
164 |
|
165 .. _install-django-code: |
|
166 |
|
167 Install the Django code |
|
168 ======================= |
|
169 |
|
170 Installation instructions are slightly different depending on whether you're |
|
171 installing a distribution-specific package, downloading the latest official |
|
172 release, or fetching the latest development version. |
|
173 |
|
174 It's easy, no matter which way you choose. |
|
175 |
|
176 Installing a distribution-specific package |
|
177 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
178 |
|
179 Check the :doc:`distribution specific notes </misc/distributions>` to see if your |
|
180 platform/distribution provides official Django packages/installers. |
|
181 Distribution-provided packages will typically allow for automatic installation |
|
182 of dependencies and easy upgrade paths. |
|
183 |
|
184 .. _installing-official-release: |
|
185 |
|
186 Installing an official release |
|
187 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
188 |
|
189 1. Download the latest release from our `download page`_. |
|
190 |
|
191 2. Untar the downloaded file (e.g. ``tar xzvf Django-NNN.tar.gz``, |
|
192 where ``NNN`` is the version number of the latest release). |
|
193 If you're using Windows, you can download the command-line tool |
|
194 bsdtar_ to do this, or you can use a GUI-based tool such as 7-zip_. |
|
195 |
|
196 3. Change into the directory created in step 2 (e.g. ``cd Django-NNN``). |
|
197 |
|
198 4. If you're using Linux, Mac OS X or some other flavor of Unix, enter |
|
199 the command ``sudo python setup.py install`` at the shell prompt. |
|
200 If you're using Windows, start up a command shell with administrator |
|
201 privileges and run the command ``setup.py install``. |
|
202 |
|
203 These commands will install Django in your Python installation's |
|
204 ``site-packages`` directory. |
|
205 |
|
206 .. _bsdtar: http://gnuwin32.sourceforge.net/packages/bsdtar.htm |
|
207 .. _7-zip: http://www.7-zip.org/ |
|
208 |
|
209 .. _installing-development-version: |
|
210 |
|
211 Installing the development version |
|
212 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
213 |
|
214 .. admonition:: Tracking Django development |
|
215 |
|
216 If you decide to use the latest development version of Django, |
|
217 you'll want to pay close attention to `the development timeline`_, |
|
218 and you'll want to keep an eye on `the list of |
|
219 backwards-incompatible changes`_. This will help you stay on top |
|
220 of any new features you might want to use, as well as any changes |
|
221 you'll need to make to your code when updating your copy of Django. |
|
222 (For stable releases, any necessary changes are documented in the |
|
223 release notes.) |
|
224 |
|
225 .. _the development timeline: http://code.djangoproject.com/timeline |
|
226 .. _the list of backwards-incompatible changes: http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges |
|
227 |
|
228 If you'd like to be able to update your Django code occasionally with the |
|
229 latest bug fixes and improvements, follow these instructions: |
|
230 |
|
231 1. Make sure that you have Subversion_ installed, and that you can run its |
|
232 commands from a shell. (Enter ``svn help`` at a shell prompt to test |
|
233 this.) |
|
234 |
|
235 2. Check out Django's main development branch (the 'trunk') like so: |
|
236 |
|
237 .. code-block:: bash |
|
238 |
|
239 svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk |
|
240 |
|
241 3. Next, make sure that the Python interpreter can load Django's code. There |
|
242 are various ways of accomplishing this. One of the most convenient, on |
|
243 Linux, Mac OSX or other Unix-like systems, is to use a symbolic link: |
|
244 |
|
245 .. code-block:: bash |
|
246 |
|
247 ln -s WORKING-DIR/django-trunk/django SITE-PACKAGES-DIR/django |
|
248 |
|
249 (In the above line, change ``SITE-PACKAGES-DIR`` to match the location of |
|
250 your system's ``site-packages`` directory, as explained in the |
|
251 "Where are my ``site-packages`` stored?" section above. Change WORKING-DIR |
|
252 to match the full path to your new ``django-trunk`` directory.) |
|
253 |
|
254 Alternatively, you can define your ``PYTHONPATH`` environment variable |
|
255 so that it includes the ``django-trunk`` directory. This is perhaps the |
|
256 most convenient solution on Windows systems, which don't support symbolic |
|
257 links. (Environment variables can be defined on Windows systems `from the |
|
258 Control Panel`_.) |
|
259 |
|
260 .. admonition:: What about Apache and mod_python? |
|
261 |
|
262 If you take the approach of setting ``PYTHONPATH``, you'll need to |
|
263 remember to do the same thing in your Apache configuration once you |
|
264 deploy your production site. Do this by setting ``PythonPath`` in your |
|
265 Apache configuration file. |
|
266 |
|
267 More information about deployment is available, of course, in our |
|
268 :doc:`How to use Django with mod_python </howto/deployment/modpython>` |
|
269 documentation. |
|
270 |
|
271 4. On Unix-like systems, create a symbolic link to the file |
|
272 ``django-trunk/django/bin/django-admin.py`` in a directory on your system |
|
273 path, such as ``/usr/local/bin``. For example: |
|
274 |
|
275 .. code-block:: bash |
|
276 |
|
277 ln -s WORKING-DIR/django-trunk/django/bin/django-admin.py /usr/local/bin |
|
278 |
|
279 (In the above line, change WORKING-DIR to match the full path to your new |
|
280 ``django-trunk`` directory.) |
|
281 |
|
282 This simply lets you type ``django-admin.py`` from within any directory, |
|
283 rather than having to qualify the command with the full path to the file. |
|
284 |
|
285 On Windows systems, the same result can be achieved by copying the file |
|
286 ``django-trunk/django/bin/django-admin.py`` to somewhere on your system |
|
287 path, for example ``C:\Python24\Scripts``. |
|
288 |
|
289 You *don't* have to run ``python setup.py install``, because you've already |
|
290 carried out the equivalent actions in steps 3 and 4. |
|
291 |
|
292 When you want to update your copy of the Django source code, just run the |
|
293 command ``svn update`` from within the ``django-trunk`` directory. When you do |
|
294 this, Subversion will automatically download any changes. |
|
295 |
|
296 .. _`download page`: http://www.djangoproject.com/download/ |
|
297 .. _Subversion: http://subversion.tigris.org/ |
|
298 .. _from the Control Panel: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sysdm_advancd_environmnt_addchange_variable.mspx |