In general, GeoDjango installation requires:
Details for each of the requirements and installation instructions are provided in the sections below. In addition, platform-specific instructions are available for:
Use the Source
Because GeoDjango takes advantage of the latest in the open source geospatial software technology, recent versions of the libraries are necessary. If binary packages aren’t available for your platform, installation from source may be required. When compiling the libraries from source, please follow the directions closely, especially if you’re a beginner.
Python and Django¶
Because GeoDjango is included with Django, please refer to Django’s installation instructions for details on how to install.
PostgreSQL (with PostGIS), MySQL (mostly with MyISAM engine), Oracle, and SQLite (with SpatiaLite) are the spatial databases currently supported.
PostGIS is recommended, because it is the most mature and feature-rich open source spatial database.
The geospatial libraries required for a GeoDjango installation depends on the spatial database used. The following lists the library requirements, supported versions, and any notes for each of the supported database backends:
|Database||Library Requirements||Supported Versions||Notes|
|PostgreSQL||GEOS, GDAL, PROJ.4, PostGIS||9.3+||Requires PostGIS.|
|MySQL||GEOS, GDAL||5.5+||Not OGC-compliant; limited functionality.|
|Oracle||GEOS, GDAL||12.1+||XE not supported.|
|SQLite||GEOS, GDAL, PROJ.4, SpatiaLite||3.6.+||Requires SpatiaLite 4.0+|
See also this comparison matrix on the OSGeo Wiki for PostgreSQL/PostGIS/GEOS/GDAL possible combinations.
ENGINE setting to one of the spatial
Like other Django contrib applications, you will only need to add
INSTALLED_APPS in your settings.
This is so that the
gis templates can be located – if not done, then
features such as the geographic admin or KML sitemaps will not function properly.
If you can’t find the solution to your problem here then participate in the community! You can:
- Join the
#geodjangoIRC channel on Freenode. Please be patient and polite – while you may not get an immediate response, someone will attempt to answer your question as soon as they see it.
- Ask your question on the GeoDjango mailing list.
- File a ticket on the Django trac if you think there’s a bug. Make sure to provide a complete description of the problem, versions used, and specify the component as “GIS”.
Library environment settings¶
By far, the most common problem when installing GeoDjango is that the external shared libraries (e.g., for GEOS and GDAL) cannot be located.  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.
LD_LIBRARY_PATH environment variable¶
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
to be included in the
LD_LIBRARY_PATH variable. For example, the user
could place the following in their bash profile:
Setting system library path¶
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
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
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
module) to discover libraries. The
find_library routine uses a program
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.
binutils package may be installed on Debian and Ubuntu systems using the
$ 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 macOS, users have several different options for installing GeoDjango. These options are:
- Postgres.app (easiest and recommended)
- KyngChaos packages
- Building from source
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 macOS comes with Python installed, users can use framework installers provided by the Python Software Foundation. An advantage to using the installer is that macOS’s Python will remain “pristine” for internal operating system use.
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:
Postgres.app is a standalone PostgreSQL server
that includes the PostGIS extension. You will also need to install
libgeoip with Homebrew.
After installing Postgres.app, add the following to your
you can run the package’s programs from the command-line. Replace
the version of PostgreSQL in the Postgres.app you installed:
You can check if the path is set up correctly by typing
which psql at a
Homebrew provides “recipes” for building binaries and packages from source. It provides recipes for the GeoDjango prerequisites on Macintosh computers running macOS. Because Homebrew still builds the software from source, Xcode is required.
$ 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 macOS without compiling them from source. However, Xcode is still necessary for compiling the Python database adapters psycopg2 (for PostGIS).
SpatiaLite users should consult the macOS-specific instructions section after installing the packages for additional instructions.
Download the framework packages for:
- SQLite3 (includes the SpatiaLite library)
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
.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
psycopg2 may be installed using the following command:
$ pip install psycopg2
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. Different packages are available (starting
django-gis), depending on which version of Python you want to use.
MacPorts may be used to install GeoDjango prerequisites on computers running macOS. Because MacPorts still builds the software from source, Xcode is required.
$ sudo port install postgresql93-server $ sudo port install geos $ sudo port install proj $ sudo port install postgis $ sudo port install gdal +geos $ sudo port install libgeoip
You will also have to modify the
PATH in your
that the MacPorts programs are accessible from the command-line:
In addition, add the
DYLD_FALLBACK_LIBRARY_PATH setting so that
the libraries can be found by Python:
Proceed through the following sections sequentially in order to install GeoDjango on Windows.
First, download the latest PostgreSQL 9.x installer from the EnterpriseDB website. After downloading, simply run the installer, follow the on-screen directions, and keep the default options unless you know the consequences of changing them.
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.
If installed successfully, the PostgreSQL server will run in the
background each time the system as started as a Windows service.
psql command window.
From within the Application Stack Builder (to run outside of the installer,), select from the drop down menu. Next, expand the menu tree and select .
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).
You will be prompted to enter your
postgres database superuser
password in the ‘Database Connection Information’ dialog.
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. 
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 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.
Modify Windows environment¶
In order to use GeoDjango, you will need to add your Python and OSGeo4W
directories to your Windows system
Path, as well as create
PROJ_LIB environment variables. The following set of commands,
cmd.exe, will set this up:
set OSGEO4W_ROOT=C:\OSGeo4W set PYTHON_ROOT=C:\Python3X 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%"
Administrator privileges are required to execute these commands.
To do this, create a
bat script with the commands, right-click it, and
select . You need to log out and log
back in again for the settings to take effect.
If you customized the Python or OSGeo4W installation directories,
then you will need to modify the
Install Django and set up database¶
Finally, install Django on your system.
|||GeoDjango uses the |