---
title: "GeoDjango のインストール"
version: 6.1
locale: ja
source: https://docs.djangoproject.com/ja/6.1/ref/contrib/gis/install/
canonical: https://djangodocs.dev/ja/6.1/ref/contrib/gis/install/
---
# GeoDjango のインストール

## 概要

通常、GeoDjango のインストールには次のものが必要です:

1. [Python と Django](#django)
2. [空間データベース (Spatial database)](#spatial-database)
3. [地理空間ライブラリ (Geospatial library)](/ja/6.1/ref/contrib/gis/install/geolibs/#geolibs-list)

各要件の詳細とインストール手順については、以下のセクションを参照してください。また、プラットフォーム別の手順もあります:

- [macOS](#macos)
- [Windows](#windows)

> **ソースを使う**
>
> GeoDjango はオープンソースの地理空間ソフトウェア技術を最新のものを活用しているため、最新バージョンのライブラリが必要です。プラットフォームにバイナリパッケージが提供されていない場合は、ソースからのインストールが必要になるかもしれません。ソースからライブラリをコンパイルする際には、特に初心者の場合は指示に注意してください。

## 必要条件

### Python と Django

GeoDjango は Django に同梱されていますので、インストール方法の詳細は Django の [インストール手順](/ja/6.1/topics/install/#installing-official-release) を参照してください。

### 空間データベース (Spatial database)

現在サポートされている空間データベースは、PostgreSQL (with PostGIS)、MySQL、Oracle、SQLite (with SpatiaLite) です。

> **Note**
>
> PostGISは、最も成熟した機能豊富なオープンソースの空間データベースであるため、推奨されています。

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+ | [機能制限があります](/ja/6.1/ref/contrib/gis/db-api/#mysql-spatial-limitations) 。 |
| 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](https://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS) も参照してください。

## インストール

### 地理空間ライブラリ (Geospatial library)

- [地理空間ライブラリのインストール](/ja/6.1/ref/contrib/gis/install/geolibs/)

### データベースのインストール

- [PostGIS のインストール](/ja/6.1/ref/contrib/gis/install/postgis/)
- [SpatiaLite のインストール](/ja/6.1/ref/contrib/gis/install/spatialite/)

### [`DATABASES`](/ja/6.1/ref/settings/#std-setting-DATABASES) の設定

[`ENGINE`](/ja/6.1/ref/settings/#std-setting-DATABASE-ENGINE) 設定を、[空間 (spatial) バックエンド](/ja/6.1/ref/contrib/gis/db-api/#spatial-backends) の1つに設定してください。

### `django.contrib.gis` を [`INSTALLED_APPS`](/ja/6.1/ref/settings/#std-setting-INSTALLED_APPS) に追加します。

他の Django contrib アプリケーションと同様に、設定の [`INSTALLED_APPS`](/ja/6.1/ref/settings/#std-setting-INSTALLED_APPS) に [`django.contrib.gis`](/ja/6.1/ref/contrib/gis/#module-django.contrib.gis) を追加するだけです。これは `gis` テンプレートを配置するためです。そうしないと、地理管理や KML サイトマップのような機能が正しく動作しません。

## トラブルシューティング

問題の解決策がここに見つからない場合は、コミュニティに参加してみてください！以下のようなことができます:

- [GeoDjango](https://forum.djangoproject.com/c/internals/geodjango/13) フォーラムで質問してください。
- File a ticket on the [Django trac](https://code.djangoproject.com/newticket) 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".

### ライブラリの環境設定

GeoDjango をインストールする際に最もよくある問題は、外部の共有ライブラリ (例えば GEOS や GDAL) が見つからないというものです [^1] 。通常、この問題の原因は、オペレーティングシステムがソースからビルドされたライブラリがインストールされたディレクトリを認識していないことです。

通常、ライブラリのパスは、個々のユーザーごとに環境変数を設定するか、システム全体のライブラリ パスを構成することで設定できます。

#### `LD_LIBRARY_PATH` 環境変数

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:

```shell
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:

```shell
$ 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:

```shell
# crle -l $OLD_PATH:/usr/local/lib
```

#### `binutils` をインストールする

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 システムでは以下のコマンドを使用してインストールできます:

```shell
$ sudo apt-get install binutils
```

Red Hat および CentOS システムでも同様です:

```shell
$ sudo yum install binutils
```

## プラットフォーム固有の手順

### macOS

macOS では様々なパッケージングシステムが利用できるため、ユーザは GeoDjango をインストールするのにいくつかの異なる選択肢があります。これらのオプションは以下の通りです:

- [Postgres.app](#postgresapp) (最も簡単、推奨)
- [Homebrew](#homebrew)
- [Fink](#fink)
- [MacPorts](#macports)
- [ソースコードからビルドする](/ja/6.1/ref/contrib/gis/install/geolibs/#build-from-source)

このセクションには、Python Software Foundation が提供するパッケージから [Python](#macos-python) のアップグレード版をインストールする手順も含まれていますが、これは必須ではありません。

#### Python

Although macOS comes with Python installed, users can use [framework
installers](https://www.python.org/ftp/python/) 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.

> **Note**
>
> コマンドラインで `python` を入力したときに新しいバージョンの Python が使われるように、`.profile` ファイルの `PATH` 環境変数を変更する必要があります:
>
> ```shell
> export PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH
> ```

#### Postgres.app

[Postgres.app](https://postgresapp.com/) is a standalone PostgreSQL server
that includes the PostGIS extension. You will also need to install `gdal`
with [Homebrew](#homebrew).

Postgres.appをインストールした後、コマンドラインからパッケージのプログラムを実行できるように、 `.bash_profile` に以下を追加してください。 `X.Y` をインストールした Postgres.app の PostgreSQL のバージョンに置き換えてください:

```bash
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/X.Y/bin
```

ターミナルプロンプトで `which psql` と入力して、パスが正しく設定されているかを確認できます。

#### Homebrew

[Homebrew](https://brew.sh/) は、ソースコードからバイナリおよびパッケージを構築するための「レシピ」を提供します。これは、macOS を実行している Macintosh コンピュータ上で GeoDjango の前提条件のためのレシピを提供しています。Homebrew はソフトウェアをソースコードから構築するため、 [Xcode](https://developer.apple.com/xcode/) が必要となります。

概要:

```shell
$ brew install postgresql
$ brew install postgis
$ brew install gdal
```

##### Fink

[Kurt Schwehr](https://schwehr.blogspot.com/) は [Fink](https://www.finkproject.org/) パッケージシステムのユーザーのために GeoDjango パッケージを作成してくれました。使用したい Python のバージョンに応じて、[Different packages are available](https://pdb.finkproject.org/pdb/browse.php?summary=django-gis) です（`django-gis` から始まります）。

#### MacPorts

[MacPorts](https://www.macports.org/) may be used to install GeoDjango prerequisites on computers
running macOS. Because MacPorts still builds the software from source,
[Xcode](https://developer.apple.com/xcode/) is required.

概要:

```shell
$ sudo port install postgresql15-server
$ sudo port install geos
$ sudo port install proj6
$ sudo port install postgis3
$ sudo port install gdal
```

> **Note**
>
> また、MacPorts のプログラムにコマンドラインからアクセスできるように、 `.profile` の `PATH` を変更する必要があります:
>
> ```shell
> export PATH=/opt/local/bin:/opt/local/lib/postgresql15/bin
> ```
>
> さらに、Python がライブラリを見つけられるように、 `DYLD_FALLBACK_LIBRARY_PATH` 設定を追加してください:
>
> ```shell
> export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:/opt/local/lib/postgresql15
> ```

### Windows

GeoDjango を Windows にインストールするには、以下のセクションを順番に進めてください。このチュートリアルでは、各アプリケーションの 64 ビット版をインストールします。

#### Python

64ビット版のPythonをインストールします。詳しくは [Python のインストール](/ja/6.1/howto/windows/) を参照してください。

#### PostgreSQL

Download the latest [PostgreSQL 15.x installer](https://www.enterprisedb.com/downloads/postgres-postgresql-downloads) from the
[EnterpriseDB](https://www.enterprisedb.com) website. After downloading, run the installer, follow the
on-screen directions, and keep the default options unless you know the
consequences of changing them.

> **Note**
>
> PostgreSQL のインストーラーは新しい `postgres` データベース管理者ユーザーを作成します。パスワードを設定する際に一度だけ入力を求められます。それを忘れないようにしてください！

インストーラーが完了すると、 "Launch Stack Builder at exit?" （スタックビルダーを終了時に起動しますか？）という質問が表示されます。これは、[PostGIS](#postgisasb) をインストールするために必要ですので、チェックを入れたままにしてください。

> **Note**
>
> If installed successfully, the PostgreSQL server will run in the background
> each time the system is started as a Windows service. A
> PostgreSQL 15 start menu group will created and contains
> shortcuts for the Application Stack Builder (ASB) as well as the
> 'SQL Shell', which will launch a `psql` command window.

#### PostGIS

Stack Builder (インストーラの外で実行するには Start ‣ PostgreSQL 15 ‣ Application Stack Builder ) から、ドロップダウンメニューから PostgreSQL 15 (x64) on port 5432 を選択して next をクリックします。 Categories ‣ Spatial Extensions メニューツリーを展開し、 PostGIS X.Y for PostgreSQL 15 を選択します。

next をクリックすると、選択したパッケージと "Download directory" を確認するプロンプトが表示されます。もう一度 next をクリックすると、PostGIS がダウンロードされ、next をクリックして PostGIS のインストーラを開始するよう求められます。インストール中はデフォルトのオプションを選択してください。インストールプロセスでは、4つの Yes/No ダイアログボックスが表示されます。

#### OSGeo4W

The [OSGeo4W installer](https://trac.osgeo.org/osgeo4w/) helps to install the PROJ, GDAL, and GEOS libraries
required by GeoDjango. First, download the [OSGeo4W installer](https://trac.osgeo.org/osgeo4w/), and
run it. Select Express Web-GIS Install 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 環境変数の変更

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:

```bat
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%"
```

> **Note**
>
> これらのコマンドを実行するには、管理者権限が必要です。これを行うには、管理者としてコマンドプロンプトを実行し、上記のコマンドを入力します。設定を有効にするには、一旦ログアウトし、再度ログインする必要があります。

> **Note**
>
> OSGeo4W のインストールディレクトリをカスタマイズした場合、それに応じて `OSGEO4W_ROOT` 変数を変更する必要があります。

#### Djangoのインストールとデータベースのセットアップ

システムにDjangoを [インストール](/ja/6.1/topics/install/#installing-official-release) します。作成する各プロジェクトに対して [仮想環境](https://docs.python.org/3/tutorial/venv.html) を作成することを推奨します。

#### psycopg

Pythonモジュール `psycopg` は Python と PostgreSQL  データベースのインターフェースを提供します。 `psycopg` は Python 仮想環境内で pip を使用してインストールできます:

```doscon
...\> py -m pip install psycopg
```

**脚注**

[^1]: GeoDjango では、共有ライブラリを探すために `ctypes.util` の [`find_library()`](https://docs.python.org/3/library/ctypes.html#ctypes.util.find_library) ルーチンが使用されています。
