Installation av GeoDjangoLink to this heading
ÖversiktLink to this heading
I allmänhet kräver installationen av GeoDjango:
spatial_databas
Detaljer för varje krav och installationsanvisningar finns i avsnitten nedan. Dessutom finns plattformsspecifika instruktioner tillgängliga för:
fönster
KravLink to this heading
Python och DjangoLink to this heading
Eftersom GeoDjango ingår i Django hänvisar vi till Djangos installationsinstruktioner för mer information om hur du installerar.
Spatial databasLink to this heading
PostgreSQL (med PostGIS), MySQL, Oracle och SQLite (med SpatiaLite) är de spatiala databaser som för närvarande stöds.
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:
Databas |
Krav på bibliotek |
Versioner som stöds |
Anteckningar |
|---|---|---|---|
PostgreSQL |
GEOS, GDAL, PROJ, PostGIS |
15+ |
Kräver PostGIS. |
MySQL |
GEOS, GDAL |
8.4+ |
|
Oracle |
GEOS, GDAL |
19+ |
XE stöds inte. |
SQLite |
GEOS, GDAL, PROJ, SpatiaLite |
3.37.0+ |
Kräver SpatiaLite 4.3+ |
Se även `den här jämförelsematrisen`__ på OSGeo Wiki för PostgreSQL / PostGIS /GEOS / GDAL möjliga kombinationer.
InstallationLink to this heading
Geospatiala bibliotekLink to this heading
Installation av databasLink to this heading
DATABASER konfigurationLink to this heading
Ange inställningen ENGINE till en av spatial backends.
Lägg till django.contrib.gis i INSTALLED_APPSLink to this heading
Precis som andra Django Contrib-applikationer behöver du bara lägga till django.contrib.gis till INSTALLED_APPS i dina inställningar. Detta är så att gis-mallarna kan lokaliseras - om det inte görs kommer funktioner som den geografiska administratören eller KML-webbplatskartor inte att fungera korrekt.
FelsökningLink to this heading
Om du inte hittar lösningen på ditt problem här kan du delta i gemenskapen! Detta kan du göra:
Ställ din fråga på forumet `GeoDjango`__.
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”.
Inställningar för biblioteksmiljöLink to this heading
Det överlägset vanligaste problemet vid installation av GeoDjango är att de externa delade biblioteken (t.ex. för GEOS och GDAL) inte kan hittas. [Orsaken till detta problem är vanligtvis att operativsystemet inte känner till den katalog där biblioteken som byggts från källan installerades.
I allmänhet kan bibliotekssökvägen ställas in för varje användare genom att ange en miljövariabel eller genom att konfigurera bibliotekssökvägen för hela systemet.
miljövariabeln LD_LIBRARY_PATHLink to this heading
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
Ställa in sökväg för systembibliotekLink to this heading
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
Installera binutilsLink to this heading
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.
Paketet binutils kan installeras på Debian- och Ubuntu-system med följande kommando:
$ sudo apt-get install binutils
På samma sätt på Red Hat- och CentOS-system:
$ sudo yum install binutils
Plattformsspecifika instruktionerLink to this heading
macOSLink to this heading
På grund av de olika paketeringssystemen som finns tillgängliga för macOS har användarna flera olika alternativ för att installera GeoDjango. Dessa alternativ är:
Postgres.app (enklast och rekommenderas)
bygga_från_källa
Detta avsnitt innehåller även instruktioner för att installera en uppgraderad version av Python från paket som tillhandahålls av Python Software Foundation, men detta är inte nödvändigt.
PythonLink to this heading
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.
Postgres.appLink to this heading
Postgres.app is a standalone PostgreSQL server
that includes the PostGIS extension. You will also need to install gdal
with Hemmabryggare.
När du har installerat Postgres.app lägger du till följande i din .bash_profile så att du kan köra paketets program från kommandoraden. Ersätt X.Y med versionen av PostgreSQL i Postgres.app som du installerade:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/X.Y/bin
Du kan kontrollera om sökvägen är korrekt inställd genom att skriva which psql i en terminalprompt.
HemmabryggareLink to this heading
`Homebrew`__ tillhandahåller ”recept” för att bygga binära filer och paket från källan. Det ger recept för GeoDjango-förutsättningarna på Macintosh-datorer som kör macOS. Eftersom Homebrew fortfarande bygger programvaran från källan krävs Xcode.
Sammanfattning:
$ brew install postgresql
$ brew install postgis
$ brew install gdal
FinkLink to this heading
`Kurt Schwehr`__ har varit snäll nog att skapa GeoDjango-paket för användare av `Fink`__-paketsystemet. olika paket finns tillgängliga (börjar med django-gis), beroende på vilken version av Python du vill använda.
MacPortsLink to this heading
`MacPorts`__ may be used to install GeoDjango prerequisites on computers running macOS. Because MacPorts still builds the software from source, Xcode is required.
Sammanfattning:
$ sudo port install postgresql15-server
$ sudo port install geos
$ sudo port install proj6
$ sudo port install postgis3
$ sudo port install gdal
FönsterLink to this heading
Fortsätt genom följande avsnitt i tur och ordning för att installera GeoDjango på Windows. I denna handledning kommer vi att installera 64-bitarsversioner av varje applikation.
PythonLink to this heading
Installera en 64-bitarsversion av Python. Se Installera Python för ytterligare information.
PostgreSQLLink to this heading
Download the latest `PostgreSQL 15.x installer`__ from the `EnterpriseDB`__ website. After downloading, run the installer, follow the on-screen directions, and keep the default options unless you know the consequences of changing them.
När installationsprogrammet är klart kommer det att fråga om ”Launch Stack Builder at exit?” – håll detta markerat, eftersom det är nödvändigt att installera PostGIS.
PostGISLink to this heading
Från Stack Builder (för att köra utanför installationsprogrammet, ), välj från rullgardinsmenyn och klicka på nästa. Expandera menyträd och välj .
När du har klickat på nästa uppmanas du att bekräfta det valda paketet och ”Download directory”. Klicka på nästa igen, detta kommer att ladda ner PostGIS och du kommer att bli ombedd att klicka på nästa för att starta PostGIS-installationsprogrammet. Välj standardalternativ under installationen. Installationsprocessen innehåller fyra Ja/Nej-dialogrutor, standardalternativet för alla fyra är ”Nej”.
OSGeo4WLink to this heading
The OSGeo4W installer helps to install the PROJ, 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. If any other packages are enabled by default, they are not required by GeoDjango and may be unchecked safely. After clicking next and accepting the license agreements, the packages will be automatically downloaded and installed, after which you may exit the installer.
Ändra Windows-miljönLink to this heading
In order to use GeoDjango, you will need to add your 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. Restart your device
once this is complete for new environment variables to be recognized:
set OSGEO4W_ROOT=C:\OSGeo4W
set GDAL_DATA=%OSGEO4W_ROOT%\apps\gdal\share\gdal
set PROJ_LIB=%OSGEO4W_ROOT%\share\proj
set PATH=%PATH%;%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%"
Installera Django och konfigurera databasenLink to this heading
Installera Django på ditt system. Det rekommenderas att du skapar en virtuell miljö för varje projekt du skapar.
psycopgLink to this heading
Python-modulen `` psycopg`` tillhandahåller gränssnittet mellan Python och PostgreSQL-databasen. psycopg kan installeras via pip inom din virtuella Python-miljö:
...\> py -m pip install psycopg
Fotnoter