GeoDjango のインストールLink to this heading
概要Link to this heading
通常、GeoDjango のインストールには次のものが必要です:
各要件の詳細とインストール手順については、以下のセクションを参照してください。また、プラットフォーム別の手順もあります:
必要条件Link to this heading
Python と DjangoLink to this heading
GeoDjango は Django に同梱されていますので、インストール方法の詳細は Django の インストール手順 を参照してください。
空間データベース (Spatial database)Link to this heading
現在サポートされている空間データベースは、PostgreSQL (with PostGIS)、MySQL、Oracle、SQLite (with SpatiaLite) です。
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:
データベース |
ライブラリの要件 |
サポートされるバージョン |
備考 |
|---|---|---|---|
PostgreSQL |
GEOS, GDAL, PROJ, PostGIS |
15+ |
PostGIS が必要です。 |
MySQL |
GEOS, GDAL |
8.4+ |
|
Oracle |
GEOS, GDAL |
19+ |
XE not supported. |
SQLite |
GEOS, GDAL, PROJ, SpatiaLite |
3.37.0+ |
Requires SpatiaLite 4.3+ |
PostgreSQL/PostGIS/GEOS/GDAL の可能な組み合わせについては、OSGeo Wikiの this comparison matrix も参照してください。
インストールLink to this heading
地理空間ライブラリ (Geospatial library)Link to this heading
データベースのインストールLink to this heading
DATABASES の設定Link to this heading
ENGINE 設定を、空間 (spatial) バックエンド の1つに設定してください。
django.contrib.gis を INSTALLED_APPS に追加します。Link to this heading
他の Django contrib アプリケーションと同様に、設定の INSTALLED_APPS に django.contrib.gis を追加するだけです。これは gis テンプレートを配置するためです。そうしないと、地理管理や KML サイトマップのような機能が正しく動作しません。
トラブルシューティングLink to this heading
問題の解決策がここに見つからない場合は、コミュニティに参加してみてください!以下のようなことができます:
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".
ライブラリの環境設定Link to this heading
GeoDjango をインストールする際に最もよくある問題は、外部の共有ライブラリ (例えば GEOS や GDAL) が見つからないというものです [1] 。通常、この問題の原因は、オペレーティングシステムがソースからビルドされたライブラリがインストールされたディレクトリを認識していないことです。
通常、ライブラリのパスは、個々のユーザーごとに環境変数を設定するか、システム全体のライブラリ パスを構成することで設定できます。
LD_LIBRARY_PATH 環境変数Link 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
システムライブラリのパスを設定するLink 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
binutils をインストールするLink 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.
binutils パッケージは、Debian および Ubuntu システムでは以下のコマンドを使用してインストールできます:
$ sudo apt-get install binutils
Red Hat および CentOS システムでも同様です:
$ sudo yum install binutils
プラットフォーム固有の手順Link to this heading
macOSLink to this heading
macOS では様々なパッケージングシステムが利用できるため、ユーザは GeoDjango をインストールするのにいくつかの異なる選択肢があります。これらのオプションは以下の通りです:
Postgres.app (最も簡単、推奨)
このセクションには、Python Software Foundation が提供するパッケージから Python のアップグレード版をインストールする手順も含まれていますが、これは必須ではありません。
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 Homebrew.
Postgres.appをインストールした後、コマンドラインからパッケージのプログラムを実行できるように、 .bash_profile に以下を追加してください。 X.Y をインストールした Postgres.app の PostgreSQL のバージョンに置き換えてください:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/X.Y/bin
ターミナルプロンプトで which psql と入力して、パスが正しく設定されているかを確認できます。
HomebrewLink to this heading
Homebrew は、ソースコードからバイナリおよびパッケージを構築するための「レシピ」を提供します。これは、macOS を実行している Macintosh コンピュータ上で GeoDjango の前提条件のためのレシピを提供しています。Homebrew はソフトウェアをソースコードから構築するため、 Xcode が必要となります。
概要:
$ brew install postgresql
$ brew install postgis
$ brew install gdal
FinkLink to this heading
Kurt Schwehr は Fink パッケージシステムのユーザーのために GeoDjango パッケージを作成してくれました。使用したい Python のバージョンに応じて、Different packages are available です(django-gis から始まります)。
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.
概要:
$ sudo port install postgresql15-server
$ sudo port install geos
$ sudo port install proj6
$ sudo port install postgis3
$ sudo port install gdal
WindowsLink to this heading
GeoDjango を Windows にインストールするには、以下のセクションを順番に進めてください。このチュートリアルでは、各アプリケーションの 64 ビット版をインストールします。
PythonLink to this heading
64ビット版のPythonをインストールします。詳しくは Python のインストール を参照してください。
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.
インストーラーが完了すると、 "Launch Stack Builder at exit?" (スタックビルダーを終了時に起動しますか?)という質問が表示されます。これは、PostGIS をインストールするために必要ですので、チェックを入れたままにしてください。
PostGISLink to this heading
Stack Builder (インストーラの外で実行するには ) から、ドロップダウンメニューから を選択して next をクリックします。 メニューツリーを展開し、 を選択します。
next をクリックすると、選択したパッケージと "Download directory" を確認するプロンプトが表示されます。もう一度 next をクリックすると、PostGIS がダウンロードされ、next をクリックして PostGIS のインストーラを開始するよう求められます。インストール中はデフォルトのオプションを選択してください。インストールプロセスでは、4つの Yes/No ダイアログボックスが表示されます。
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.
Windows 環境変数の変更Link 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%"
DjangoのインストールとデータベースのセットアップLink to this heading
psycopgLink to this heading
Pythonモジュール psycopg は Python と PostgreSQL データベースのインターフェースを提供します。 psycopg は Python 仮想環境内で pip を使用してインストールできます:
...\> py -m pip install psycopg
脚注