En général, l’installation de GeoDjango requiert :
Des détails au sujet de chaque exigence et des instructions d’installation sont fournies dans les sections ci-dessous. De plus, des instructions spécifiques à des plates-formes particulières sont disponibles pour :
Use the Source
Comme GeoDjango tire profit des derniers développements de la technologie logicielle géospatiale libre, des versions récentes des bibliothèques sont nécessaires. Si des paquets binaires ne sont pas disponibles sur votre plate-forme, il peut être nécessaire d’installer à partir des sources. Lors de la compilation des bibliothèques à partir des sources, suivez attentivement les consignes, particulièrement si vous êtes débutant.
Comme GeoDjango est inclus dans Django, référez-vous aux instructions d’installation de Django pour des détails sur l’installation.
PostgreSQL (avec PostGIS), MySQL (essentiellement avec le moteur MyISAM), Oracle et SQLite (avec SpatiaLite) sont les bases de données spatiales actuellement prises en charge.
Note
PostGIS est recommandé, car c’est la base de données spatiale libre la plus mature et riche en fonctionnalités.
Les bibliothèques géospatiales requises pour une installation de GeoDjango dépendent de la base de données spatiale utilisée. Le tableau ci-après présente les bibliothèques requises, les versions prises en charge et d’éventuelles notes pour les différents moteurs de base de données :
Base de données |
Bibliothèques requises |
Versions prises en charge |
Notes |
---|---|---|---|
PostgreSQL | GEOS, PROJ.4, PostGIS | 8.4+ | Exige PostGIS. |
MySQL | GEOS | 5.x | Non conforme avec OGC ; fonctionnalités limitées. |
Oracle | GEOS | 10.2, 11 | XE non pris en charge ; non testé avec 9. |
SQLite | GEOS, GDAL, PROJ.4, SpatiaLite | 3.6.+ | Nécessite SpatiaLite 2.3+, pysqlite2 2.5+ |
Voir aussi cette matrice comparative sur le Wiki OSGeo pour des combinaisons possibles entre PostgreSQL/PostGIS/GEOS/GDAL.
Comme pour d’autres applications contribuées dans Django, il suffit d’ajouter django.contrib.gis à INSTALLED_APPS dans vos réglages. Ceci afin que les gabarits gis puissent être découverts ; dans le cas contraire, certaines fonctions comme l’interface d’administration géographique ou les plans de sites KML ne fonctionneraient pas correctement.
Note
Si vous utilisez PostGIS 1.4 ou supérieur, vous pouvez sauter cette étape. La ligne nécessaire est déjà incluse dans le contenu par défaut de la table spatial_ref_sys.
Dans le but d’effectuer des transformations de base de données dans la projection dite « Google » (une projection Mercator sphérique utilisée par Google Maps), une ligne doit être ajoutée à la table spatial_ref_sys de votre base de données spatiale. Lancez le shell Django de votre projet et exécutez la fonction add_srs_entry:
$ python manage.py shell
>>> from django.contrib.gis.utils import add_srs_entry
>>> add_srs_entry(900913)
Ceci ajoute une ligne pour le SRID 900913 à la table spatial_ref_sys (ou son équivalent), ce qui permet à la base de données spatiale de transformer des coordonnées dans cette projection. Il suffit d’exécuter cette commande une seule fois par base de données spatiale.
Si vous ne trouvez pas de solution à votre problème sur cette page, participez alors à la communauté ! Vous pouvez :
Rejoindre le canal IRC #geodjango sur FreeNode. Soyez patient et poli ; même si vous n’obtenez pas de réponse immédiate, quelqu’un essaiera de répondre à votre question au moment où il la lira.
Poser votre question sur la liste de diffusion GeoDjango (en anglais).
Créer un ticket dans le trac de Django si vous pensez qu’il y a un bogue. Prenez soin de fournir une description complète du problème, les versions utilisées et indiquez le composant « GIS ».
By far, the most common problem when installing GeoDjango is that the external shared libraries (e.g., for GEOS and GDAL) cannot be located. [1] Typically, the cause of this problem is that the operating system isn’t aware of the directory where the libraries built from source were installed.
In general, the library path may be set on a per-user basis by setting an environment variable, or by configuring the library path for the entire system.
A user may set this environment variable to customize the library paths they want to use. The typical library directory for software built from source is /usr/local/lib. Thus, /usr/local/lib needs to be included in the LD_LIBRARY_PATH variable. For example, the user could place the following in their bash profile:
export LD_LIBRARY_PATH=/usr/local/lib
On GNU/Linux systems, there is typically a file in /etc/ld.so.conf, which may include additional paths from files in another directory, such as /etc/ld.so.conf.d. As the root user, add the custom library path (like /usr/local/lib) on a new line in ld.so.conf. This is one example of how to do so:
$ sudo echo /usr/local/lib >> /etc/ld.so.conf
$ sudo ldconfig
For OpenSolaris users, the system library path may be modified using the crle utility. Run crle with no options to see the current configuration and use crle -l to set with the new library path. Be very careful when modifying the system library path:
# crle -l $OLD_PATH:/usr/local/lib
GeoDjango uses the find_library function (from the ctypes.util Python module) to discover libraries. The find_library routine uses a program called objdump (part of the binutils package) to verify a shared library on GNU/Linux systems. Thus, if binutils is not installed on your Linux system then Python’s ctypes may not be able to find your library even if your library path is set correctly and geospatial libraries were built perfectly.
The binutils package may be installed on Debian and Ubuntu systems using the following command:
$ sudo apt-get install binutils
Similarly, on Red Hat and CentOS systems:
$ sudo yum install binutils
Because of the variety of packaging systems available for OS X, users have several different options for installing GeoDjango. These options are:
Note
Currently, the easiest and recommended approach for installing GeoDjango on OS X is to use the KyngChaos packages.
This section also includes instructions for installing an upgraded version of Python from packages provided by the Python Software Foundation, however, this is not required.
Although OS X comes with Python installed, users can use framework installers (2.6 and 2.7 are available) provided by the Python Software Foundation. An advantage to using the installer is that OS X’s Python will remain “pristine” for internal operating system use.
Note
You will need to modify the PATH environment variable in your .profile file so that the new version of Python is used when python is entered at the command-line:
export PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH
Homebrew provides “recipes” for building binaries and packages from source. It provides recipes for the GeoDjango prerequisites on Macintosh computers running OS X. Because Homebrew still builds the software from source, the Apple Developer Tools are required.
Summary:
$ brew install postgresql
$ brew install postgis
$ brew install gdal
$ brew install libgeoip
William Kyngesburye provides a number of geospatial library binary packages that make it simple to get GeoDjango installed on OS X without compiling them from source. However, the Apple Developer Tools are still necessary for compiling the Python database adapters psycopg2 (for PostGIS) and pysqlite2 (for SpatiaLite).
Note
SpatiaLite users should consult the Mac OS X-specific instructions section after installing the packages for additional instructions.
Download the framework packages for:
Install the packages in the order they are listed above, as the GDAL and SQLite packages require the packages listed before them.
Afterwards, you can also install the KyngChaos binary packages for PostgreSQL and PostGIS.
After installing the binary packages, you’ll want to add the following to your .profile to be able to run the package programs from the command-line:
export PATH=/Library/Frameworks/UnixImageIO.framework/Programs:$PATH
export PATH=/Library/Frameworks/PROJ.framework/Programs:$PATH
export PATH=/Library/Frameworks/GEOS.framework/Programs:$PATH
export PATH=/Library/Frameworks/SQLite3.framework/Programs:$PATH
export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH
export PATH=/usr/local/pgsql/bin:$PATH
After you’ve installed the KyngChaos binaries and modified your PATH, as described above, psycopg2 may be installed using the following command:
$ sudo pip install psycopg2
Note
If you don’t have pip, follow the installation instructions to install it.
Kurt Schwehr has been gracious enough to create GeoDjango packages for users of the Fink package system. The following packages are available, depending on which version of Python you want to use:
MacPorts may be used to install GeoDjango prerequisites on Macintosh computers running OS X. Because MacPorts still builds the software from source, the Apple Developer Tools are required.
Summary:
$ sudo port install postgresql83-server
$ sudo port install geos
$ sudo port install proj
$ sudo port install postgis
$ sudo port install gdal +geos
$ sudo port install libgeoip
Note
You will also have to modify the PATH in your .profile so that the MacPorts programs are accessible from the command-line:
export PATH=/opt/local/bin:/opt/local/lib/postgresql83/bin
In addition, add the DYLD_FALLBACK_LIBRARY_PATH setting so that the libraries can be found by Python:
export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:/opt/local/lib/postgresql83
Proceed through the following sections sequentially in order to install GeoDjango on Windows.
Note
These instructions assume that you are using 32-bit versions of all programs. While 64-bit versions of Python and PostgreSQL 9.x are available, 64-bit versions of spatial libraries, like GEOS and GDAL, are not yet provided by the OSGeo4W installer.
First, download the latest Python 2.7 installer from the Python Web site. Next, run the installer and keep the defaults – for example, keep ‘Install for all users’ checked and the installation path set as C:\Python27.
Note
You may already have a version of Python installed in C:\python as ESRI products sometimes install a copy there. You should still install a fresh version of Python 2.7.
First, download the latest PostgreSQL 9.x installer from the EnterpriseDB Web site. After downloading, simply run the installer, follow the on-screen directions, and keep the default options unless you know the consequences of changing them.
Note
The PostgreSQL installer creates both a new Windows user to be the ‘postgres service account’ and a postgres database superuser You will be prompted once to set the password for both accounts – make sure to remember it!
When the installer completes, it will ask to launch the Application Stack Builder (ASB) on exit – keep this checked, as it is necessary to install PostGIS.
Note
If installed successfully, the PostgreSQL server will run in the background each time the system as started as a Windows service. A PostgreSQL 9.x start menu group will created and contains shortcuts for the ASB as well as the ‘SQL Shell’, which will launch a psql command window.
From within the Application Stack Builder (to run outside of the installer, Start ‣ Programs ‣ PostgreSQL 9.x), select PostgreSQL Database Server 9.x on port 5432 from the drop down menu. Next, expand the Categories ‣ Spatial Extensions menu tree and select PostGIS 1.5 for PostgreSQL 9.x.
After clicking next, you will be prompted to select your mirror, PostGIS will be downloaded, and the PostGIS installer will begin. Select only the default options during install (e.g., do not uncheck the option to create a default PostGIS database).
Note
You will be prompted to enter your postgres database superuser password in the ‘Database Connection Information’ dialog.
The psycopg2 Python module provides the interface between Python and the PostgreSQL database. Download the latest Windows installer for your version of Python and PostgreSQL and run using the default settings. [2]
The OSGeo4W installer makes it simple to install the PROJ.4, GDAL, and GEOS libraries required by GeoDjango. First, download the OSGeo4W installer, and run it. Select Express Web-GIS Install and click next. In the ‘Select Packages’ list, ensure that GDAL is selected; MapServer and Apache are also enabled by default, but are not required by GeoDjango and may be unchecked safely. After clicking next, the packages will be automatically downloaded and installed, after which you may exit the installer.
In order to use GeoDjango, you will need to add your Python and OSGeo4W directories to your Windows system Path, as well as create GDAL_DATA and PROJ_LIB environment variables. The following set of commands, executable with cmd.exe, will set this up:
set OSGEO4W_ROOT=C:\OSGeo4W
set PYTHON_ROOT=C:\Python27
set GDAL_DATA=%OSGEO4W_ROOT%\share\gdal
set PROJ_LIB=%OSGEO4W_ROOT%\share\proj
set PATH=%PATH%;%PYTHON_ROOT%;%OSGEO4W_ROOT%\bin
reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /f /d "%PATH%"
reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v GDAL_DATA /t REG_EXPAND_SZ /f /d "%GDAL_DATA%"
reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROJ_LIB /t REG_EXPAND_SZ /f /d "%PROJ_LIB%"
For your convenience, these commands are available in the executable batch script, geodjango_setup.bat.
Note
Administrator privileges are required to execute these commands. To do this, right-click on geodjango_setup.bat and select Run as administrator. You need to log out and log back in again for the settings to take effect.
Note
If you customized the Python or OSGeo4W installation directories, then you will need to modify the OSGEO4W_ROOT and/or PYTHON_ROOT variables accordingly.
Finally, install Django on your system.
Notes de bas de page
[1] | GeoDjango uses the find_library() routine from ctypes.util to locate shared libraries. |
[2] | The psycopg2 Windows installers are packaged and maintained by Jason Erickson. |
Jan 13, 2016