index.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. ======================
  2. GeoDjango Installation
  3. ======================
  4. .. highlight:: console
  5. Overview
  6. ========
  7. In general, GeoDjango installation requires:
  8. 1. :ref:`Python and Django <django>`
  9. 2. :ref:`spatial_database`
  10. 3. :doc:`geolibs`
  11. Details for each of the requirements and installation instructions
  12. are provided in the sections below. In addition, platform-specific
  13. instructions are available for:
  14. * :ref:`macosx`
  15. * :ref:`windows`
  16. .. admonition:: Use the Source
  17. Because GeoDjango takes advantage of the latest in the open source geospatial
  18. software technology, recent versions of the libraries are necessary.
  19. If binary packages aren't available for your platform, installation from
  20. source may be required. When compiling the libraries from source, please
  21. follow the directions closely, especially if you're a beginner.
  22. Requirements
  23. ============
  24. .. _django:
  25. Python and Django
  26. -----------------
  27. Because GeoDjango is included with Django, please refer to Django's
  28. :ref:`installation instructions <installing-official-release>` for details on
  29. how to install.
  30. .. _spatial_database:
  31. Spatial database
  32. ----------------
  33. PostgreSQL (with PostGIS), MySQL (mostly with MyISAM engine), Oracle, and SQLite
  34. (with SpatiaLite) are the spatial databases currently supported.
  35. .. note::
  36. PostGIS is recommended, because it is the most mature and feature-rich
  37. open source spatial database.
  38. The geospatial libraries required for a GeoDjango installation depends
  39. on the spatial database used. The following lists the library requirements,
  40. supported versions, and any notes for each of the supported database backends:
  41. ================== ============================== ================== =========================================
  42. Database Library Requirements Supported Versions Notes
  43. ================== ============================== ================== =========================================
  44. PostgreSQL GEOS, GDAL, PROJ.4, PostGIS 9.3+ Requires PostGIS.
  45. MySQL GEOS, GDAL 5.5+ Not OGC-compliant; :ref:`limited functionality <mysql-spatial-limitations>`.
  46. Oracle GEOS, GDAL 11.2+ XE not supported.
  47. SQLite GEOS, GDAL, PROJ.4, SpatiaLite 3.6.+ Requires SpatiaLite 4.0+, pysqlite2 2.5+
  48. ================== ============================== ================== =========================================
  49. See also `this comparison matrix`__ on the OSGeo Wiki for
  50. PostgreSQL/PostGIS/GEOS/GDAL possible combinations.
  51. __ https://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS
  52. Installation
  53. ============
  54. Geospatial libraries
  55. --------------------
  56. .. toctree::
  57. :maxdepth: 1
  58. geolibs
  59. Database installation
  60. ---------------------
  61. .. toctree::
  62. :maxdepth: 1
  63. postgis
  64. spatialite
  65. Add ``django.contrib.gis`` to :setting:`INSTALLED_APPS`
  66. -------------------------------------------------------
  67. Like other Django contrib applications, you will *only* need to add
  68. :mod:`django.contrib.gis` to :setting:`INSTALLED_APPS` in your settings.
  69. This is so that the ``gis`` templates can be located -- if not done, then
  70. features such as the geographic admin or KML sitemaps will not function properly.
  71. Troubleshooting
  72. ===============
  73. If you can't find the solution to your problem here then participate in the
  74. community! You can:
  75. * Join the ``#geodjango`` IRC channel on Freenode. Please be patient and polite
  76. -- while you may not get an immediate response, someone will attempt to answer
  77. your question as soon as they see it.
  78. * Ask your question on the `GeoDjango`__ mailing list.
  79. * File a ticket on the `Django trac`__ if you think there's a bug. Make
  80. sure to provide a complete description of the problem, versions used,
  81. and specify the component as "GIS".
  82. __ https://groups.google.com/d/forum/geodjango
  83. __ https://code.djangoproject.com/newticket
  84. .. _libsettings:
  85. Library environment settings
  86. ----------------------------
  87. By far, the most common problem when installing GeoDjango is that the
  88. external shared libraries (e.g., for GEOS and GDAL) cannot be located. [#]_
  89. Typically, the cause of this problem is that the operating system isn't aware
  90. of the directory where the libraries built from source were installed.
  91. In general, the library path may be set on a per-user basis by setting
  92. an environment variable, or by configuring the library path for the entire
  93. system.
  94. ``LD_LIBRARY_PATH`` environment variable
  95. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  96. A user may set this environment variable to customize the library paths
  97. they want to use. The typical library directory for software
  98. built from source is ``/usr/local/lib``. Thus, ``/usr/local/lib`` needs
  99. to be included in the ``LD_LIBRARY_PATH`` variable. For example, the user
  100. could place the following in their bash profile::
  101. export LD_LIBRARY_PATH=/usr/local/lib
  102. Setting system library path
  103. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  104. On GNU/Linux systems, there is typically a file in ``/etc/ld.so.conf``, which may include
  105. additional paths from files in another directory, such as ``/etc/ld.so.conf.d``.
  106. As the root user, add the custom library path (like ``/usr/local/lib``) on a
  107. new line in ``ld.so.conf``. This is *one* example of how to do so::
  108. $ sudo echo /usr/local/lib >> /etc/ld.so.conf
  109. $ sudo ldconfig
  110. For OpenSolaris users, the system library path may be modified using the
  111. ``crle`` utility. Run ``crle`` with no options to see the current configuration
  112. and use ``crle -l`` to set with the new library path. Be *very* careful when
  113. modifying the system library path::
  114. # crle -l $OLD_PATH:/usr/local/lib
  115. .. _binutils:
  116. Install ``binutils``
  117. ~~~~~~~~~~~~~~~~~~~~
  118. GeoDjango uses the ``find_library`` function (from the ``ctypes.util`` Python
  119. module) to discover libraries. The ``find_library`` routine uses a program
  120. called ``objdump`` (part of the ``binutils`` package) to verify a shared
  121. library on GNU/Linux systems. Thus, if ``binutils`` is not installed on your
  122. Linux system then Python's ctypes may not be able to find your library even if
  123. your library path is set correctly and geospatial libraries were built perfectly.
  124. The ``binutils`` package may be installed on Debian and Ubuntu systems using the
  125. following command::
  126. $ sudo apt-get install binutils
  127. Similarly, on Red Hat and CentOS systems::
  128. $ sudo yum install binutils
  129. Platform-specific instructions
  130. ==============================
  131. .. _macosx:
  132. Mac OS X
  133. --------
  134. Because of the variety of packaging systems available for OS X, users have
  135. several different options for installing GeoDjango. These options are:
  136. * :ref:`postgresapp` (easiest and recommended)
  137. * :ref:`homebrew`
  138. * :ref:`kyngchaos`
  139. * :ref:`fink`
  140. * :ref:`macports`
  141. * :ref:`build_from_source`
  142. This section also includes instructions for installing an upgraded version
  143. of :ref:`macosx_python` from packages provided by the Python Software
  144. Foundation, however, this is not required.
  145. .. _macosx_python:
  146. Python
  147. ~~~~~~
  148. Although OS X comes with Python installed, users can use `framework
  149. installers`__ provided by the Python Software Foundation. An advantage to
  150. using the installer is that OS X's Python will remain "pristine" for internal
  151. operating system use.
  152. __ https://www.python.org/ftp/python/
  153. .. note::
  154. You will need to modify the ``PATH`` environment variable in your
  155. ``.profile`` file so that the new version of Python is used when
  156. ``python`` is entered at the command-line::
  157. export PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH
  158. .. _postgresapp:
  159. Postgres.app
  160. ~~~~~~~~~~~~
  161. `Postgres.app <http://postgresapp.com/>`_ is a standalone PostgreSQL server
  162. that includes the PostGIS extension. You will also need to install ``gdal`` and
  163. ``libgeoip`` with :ref:`homebrew`.
  164. After installing Postgres.app, add the following to your ``.bash_profile`` so
  165. you can run the package's programs from the command-line. Replace ``X.Y`` with
  166. the version of PostgreSQL in the Postgres.app you installed:
  167. .. code-block:: bash
  168. export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/X.Y/bin
  169. You can check if the path is set up correctly by typing ``which psql`` at a
  170. terminal prompt.
  171. .. _homebrew:
  172. Homebrew
  173. ~~~~~~~~
  174. `Homebrew`__ provides "recipes" for building binaries and packages from source.
  175. It provides recipes for the GeoDjango prerequisites on Macintosh computers
  176. running OS X. Because Homebrew still builds the software from source, the
  177. `Apple Developer Tools`_ are required.
  178. Summary::
  179. $ brew install postgresql
  180. $ brew install postgis
  181. $ brew install gdal
  182. $ brew install libgeoip
  183. __ http://brew.sh/
  184. .. _Apple Developer Tools: https://developer.apple.com/technologies/tools/
  185. .. _kyngchaos:
  186. KyngChaos packages
  187. ~~~~~~~~~~~~~~~~~~
  188. William Kyngesburye provides a number of `geospatial library binary packages`__
  189. that make it simple to get GeoDjango installed on OS X without compiling
  190. them from source. However, the `Apple Developer Tools`_ are still necessary
  191. for compiling the Python database adapters :ref:`psycopg2_kyngchaos` (for PostGIS)
  192. and `pysqlite2 <https://pypi.python.org/pypi/pysqlite>`_ (for SpatiaLite).
  193. .. note::
  194. SpatiaLite users should consult the :ref:`spatialite_macosx` section
  195. after installing the packages for additional instructions.
  196. Download the framework packages for:
  197. * UnixImageIO
  198. * PROJ
  199. * GEOS
  200. * SQLite3 (includes the SpatiaLite library)
  201. * GDAL
  202. Install the packages in the order they are listed above, as the GDAL and SQLite
  203. packages require the packages listed before them.
  204. Afterwards, you can also install the KyngChaos binary packages for `PostgreSQL
  205. and PostGIS`__.
  206. After installing the binary packages, you'll want to add the following to
  207. your ``.profile`` to be able to run the package programs from the command-line::
  208. export PATH=/Library/Frameworks/UnixImageIO.framework/Programs:$PATH
  209. export PATH=/Library/Frameworks/PROJ.framework/Programs:$PATH
  210. export PATH=/Library/Frameworks/GEOS.framework/Programs:$PATH
  211. export PATH=/Library/Frameworks/SQLite3.framework/Programs:$PATH
  212. export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH
  213. export PATH=/usr/local/pgsql/bin:$PATH
  214. __ http://www.kyngchaos.com/software/frameworks
  215. __ http://www.kyngchaos.com/software/postgres
  216. .. _psycopg2_kyngchaos:
  217. psycopg2
  218. ^^^^^^^^
  219. After you've installed the KyngChaos binaries and modified your ``PATH``, as
  220. described above, ``psycopg2`` may be installed using the following command::
  221. $ pip install psycopg2
  222. .. note::
  223. If you don't have ``pip``, follow the :ref:`installation instructions
  224. <installing-official-release>` to install it.
  225. .. _fink:
  226. Fink
  227. ^^^^
  228. `Kurt Schwehr`__ has been gracious enough to create GeoDjango packages for users
  229. of the `Fink`__ package system. `Different packages are available`__ (starting
  230. with ``django-gis``), depending on which version of Python you want to use.
  231. __ https://schwehr.blogspot.com/
  232. __ http://www.finkproject.org/
  233. __ http://pdb.finkproject.org/pdb/browse.php?summary=django-gis
  234. .. _macports:
  235. MacPorts
  236. ~~~~~~~~
  237. `MacPorts`__ may be used to install GeoDjango prerequisites on Macintosh
  238. computers running OS X. Because MacPorts still builds the software from source,
  239. the `Apple Developer Tools`_ are required.
  240. Summary::
  241. $ sudo port install postgresql93-server
  242. $ sudo port install geos
  243. $ sudo port install proj
  244. $ sudo port install postgis
  245. $ sudo port install gdal +geos
  246. $ sudo port install libgeoip
  247. .. note::
  248. You will also have to modify the ``PATH`` in your ``.profile`` so
  249. that the MacPorts programs are accessible from the command-line::
  250. export PATH=/opt/local/bin:/opt/local/lib/postgresql93/bin
  251. In addition, add the ``DYLD_FALLBACK_LIBRARY_PATH`` setting so that
  252. the libraries can be found by Python::
  253. export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:/opt/local/lib/postgresql93
  254. __ https://www.macports.org/
  255. .. _windows:
  256. Windows
  257. -------
  258. Proceed through the following sections sequentially in order to install
  259. GeoDjango on Windows.
  260. .. note::
  261. These instructions assume that you are using 32-bit versions of
  262. all programs. While 64-bit versions of Python and PostgreSQL 9.x
  263. are available, 64-bit versions of spatial libraries, like
  264. GEOS and GDAL, are not yet provided by the :ref:`OSGeo4W` installer.
  265. Python
  266. ~~~~~~
  267. First, download the latest `Python 2.7 installer`__ from the Python website.
  268. Next, run the installer and keep the defaults -- for example, keep
  269. 'Install for all users' checked and the installation path set as
  270. ``C:\Python27``.
  271. .. note::
  272. You may already have a version of Python installed in ``C:\python`` as ESRI
  273. products sometimes install a copy there. *You should still install a
  274. fresh version of Python 2.7.*
  275. __ https://python.org/download/
  276. PostgreSQL
  277. ~~~~~~~~~~
  278. First, download the latest `PostgreSQL 9.x installer`__ from the
  279. `EnterpriseDB`__ website. After downloading, simply run the installer,
  280. follow the on-screen directions, and keep the default options unless
  281. you know the consequences of changing them.
  282. .. note::
  283. The PostgreSQL installer creates both a new Windows user to be the
  284. 'postgres service account' and a ``postgres`` database superuser
  285. You will be prompted once to set the password for both accounts --
  286. make sure to remember it!
  287. When the installer completes, it will ask to launch the Application Stack
  288. Builder (ASB) on exit -- keep this checked, as it is necessary to
  289. install :ref:`postgisasb`.
  290. .. note::
  291. If installed successfully, the PostgreSQL server will run in the
  292. background each time the system as started as a Windows service.
  293. A :menuselection:`PostgreSQL 9.x` start menu group will created
  294. and contains shortcuts for the ASB as well as the 'SQL Shell',
  295. which will launch a ``psql`` command window.
  296. __ http://www.enterprisedb.com/products-services-training/pgdownload
  297. __ http://www.enterprisedb.com
  298. .. _postgisasb:
  299. PostGIS
  300. ~~~~~~~
  301. From within the Application Stack Builder (to run outside of the installer,
  302. :menuselection:`Start --> Programs --> PostgreSQL 9.x`), select
  303. :menuselection:`PostgreSQL Database Server 9.x on port 5432` from the drop down
  304. menu. Next, expand the :menuselection:`Categories --> Spatial Extensions` menu
  305. tree and select :menuselection:`PostGIS X.Y for PostgreSQL 9.x`.
  306. After clicking next, you will be prompted to select your mirror, PostGIS
  307. will be downloaded, and the PostGIS installer will begin. Select only the
  308. default options during install (e.g., do not uncheck the option to create a
  309. default PostGIS database).
  310. .. note::
  311. You will be prompted to enter your ``postgres`` database superuser
  312. password in the 'Database Connection Information' dialog.
  313. psycopg2
  314. ~~~~~~~~
  315. The ``psycopg2`` Python module provides the interface between Python and the
  316. PostgreSQL database. Download the latest `Windows installer`__ for your version
  317. of Python and PostgreSQL and run using the default settings. [#]_
  318. __ http://www.stickpeople.com/projects/python/win-psycopg/
  319. .. _osgeo4w:
  320. OSGeo4W
  321. ~~~~~~~
  322. The `OSGeo4W installer`_ makes it simple to install the PROJ.4, GDAL, and GEOS
  323. libraries required by GeoDjango. First, download the `OSGeo4W installer`_,
  324. and run it. Select :menuselection:`Express Web-GIS Install` and click next.
  325. In the 'Select Packages' list, ensure that GDAL is selected; MapServer and
  326. Apache are also enabled by default, but are not required by GeoDjango and
  327. may be unchecked safely. After clicking next, the packages will be
  328. automatically downloaded and installed, after which you may exit the
  329. installer.
  330. .. _OSGeo4W installer: https://trac.osgeo.org/osgeo4w/
  331. Modify Windows environment
  332. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  333. In order to use GeoDjango, you will need to add your Python and OSGeo4W
  334. directories to your Windows system ``Path``, as well as create ``GDAL_DATA``
  335. and ``PROJ_LIB`` environment variables. The following set of commands,
  336. executable with ``cmd.exe``, will set this up:
  337. .. code-block:: bat
  338. set OSGEO4W_ROOT=C:\OSGeo4W
  339. set PYTHON_ROOT=C:\Python27
  340. set GDAL_DATA=%OSGEO4W_ROOT%\share\gdal
  341. set PROJ_LIB=%OSGEO4W_ROOT%\share\proj
  342. set PATH=%PATH%;%PYTHON_ROOT%;%OSGEO4W_ROOT%\bin
  343. reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /f /d "%PATH%"
  344. reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v GDAL_DATA /t REG_EXPAND_SZ /f /d "%GDAL_DATA%"
  345. reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROJ_LIB /t REG_EXPAND_SZ /f /d "%PROJ_LIB%"
  346. For your convenience, these commands are available in the executable batch
  347. script, :download:`geodjango_setup.bat`.
  348. .. note::
  349. Administrator privileges are required to execute these commands.
  350. To do this, right-click on :download:`geodjango_setup.bat` and select
  351. :menuselection:`Run as administrator`. You need to log out and log back in again
  352. for the settings to take effect.
  353. .. note::
  354. If you customized the Python or OSGeo4W installation directories,
  355. then you will need to modify the ``OSGEO4W_ROOT`` and/or ``PYTHON_ROOT``
  356. variables accordingly.
  357. Install Django and set up database
  358. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  359. Finally, :ref:`install Django <installing-official-release>` on your system.
  360. .. rubric:: Footnotes
  361. .. [#] GeoDjango uses the :func:`~ctypes.util.find_library` routine from
  362. ``ctypes.util`` to locate shared libraries.
  363. .. [#] The ``psycopg2`` Windows installers are packaged and maintained by
  364. `Jason Erickson <http://www.stickpeople.com/projects/python/win-psycopg/>`_.