“Django/docs/3.0.x/ref/contrib/gis/install/index”的版本间差异

来自菜鸟教程
Django/docs/3.0.x/ref/contrib/gis/install/index
跳转至:导航、​搜索
(autoload)
 
(Page commit)
 
第1行: 第1行:
 +
{{DISPLAYTITLE:GeoDjango 安装 — Django 文档}}
 
<div id="geodjango-installation" class="section">
 
<div id="geodjango-installation" class="section">
  
= GeoDjango Installation =
+
= GeoDjango 安装 =
  
 
<div id="overview" class="section">
 
<div id="overview" class="section">
  
== 概况 ==
+
== 概览 ==
  
In general, GeoDjango installation requires:
+
一般来说,GeoDjango 安装需要:
  
# [[#django|<span class="std std-ref">Python and Django</span>]]
+
# [[#django|<span class="std std-ref">Python Django</span>]]
# [[#spatial-database|<span class="std std-ref">Spatial database</span>]]
+
# [[#spatial-database|<span class="std std-ref">空间数据库</span>]]
# [[../geolibs|<span class="doc">Installing Geospatial libraries</span>]]
+
# [[../geolibs|<span class="doc">安装地理空间库</span>]]
  
Details for each of the requirements and installation instructions
+
以下各节提供了每个要求和安装说明的详细信息。 此外,平台特定的说明可用于:
are provided in the sections below. In addition, platform-specific
 
instructions are available for:
 
  
 
* [[#macos|<span class="std std-ref">macOS</span>]]
 
* [[#macos|<span class="std std-ref">macOS</span>]]
* [[#windows|<span class="std std-ref">Windows</span>]]
+
* [[#windows|<span class="std std-ref">窗户</span>]]
  
 
<div class="admonition-use-the-source admonition">
 
<div class="admonition-use-the-source admonition">
  
Use the Source
+
使用源
  
Because GeoDjango takes advantage of the latest in the open source geospatial
+
因为 GeoDjango 利用了最新的开源地理空间软件技术,所以需要最新版本的库。 如果二进制包不适用于您的平台,则可能需要从源代码安装。 从源代码编译库时,请严格按照说明进行操作,特别是如果您是初学者。
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.
 
  
  
第36行: 第31行:
 
<div id="requirements" class="section">
 
<div id="requirements" class="section">
  
== Requirements ==
+
== 要求 ==
  
 
<div id="python-and-django" class="section">
 
<div id="python-and-django" class="section">
  
 
<span id="django"></span>
 
<span id="django"></span>
=== Python and Django ===
+
=== Python Django ===
  
Because GeoDjango is included with Django, please refer to Django's
+
由于GeoDjango 包含在Django 中,详细安装方法请参考Django 的[[../../../../../topics/install#installing-official-release|安装说明]]
[[../../../../../topics/install#installing-official-release|<span class="std std-ref">installation instructions</span>]] for details on
 
how to install.
 
  
  
第52行: 第45行:
  
 
<span id="id1"></span>
 
<span id="id1"></span>
=== Spatial database ===
+
=== 空间数据库 ===
  
PostgreSQL (with PostGIS), MySQL (mostly with MyISAM engine), Oracle, and SQLite
+
目前支持的空间数据库有 PostgreSQL(带有 PostGIS)、MySQL(主要带有 MyISAM 引擎)、Oracle 和 SQLite(带有 SpatiaLite)。
(with SpatiaLite) are the spatial databases currently supported.
 
  
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
PostGIS is recommended, because it is the most mature and feature-rich
+
推荐使用 PostGIS,因为它是最成熟、功能最丰富的开源空间数据库。
open source spatial database.
 
  
  
 
</div>
 
</div>
The geospatial libraries required for a GeoDjango installation depends
+
GeoDjango 安装所需的地理空间库取决于所使用的空间数据库。 下面列出了每个支持的数据库后端的库要求、支持的版本和任何注意事项:
on the spatial database used. The following lists the library requirements,
 
supported versions, and any notes for each of the supported database backends:
 
  
 
{|
 
{|
 
!width="15%"| 数据库
 
!width="15%"| 数据库
!width="24%"| Library Requirements
+
!width="24%"| 图书馆要求
!width="15%"| Supported Versions
+
!width="15%"| 支持的版本
!width="46%"| 注意
+
!width="46%"| 笔记
 
|-
 
|-
 
| PostgreSQL
 
| PostgreSQL
| GEOS, GDAL, PROJ.4, PostGIS
+
| GEOS、GDAL、PROJ.4、PostGIS
 
| 9.5+
 
| 9.5+
| Requires PostGIS.
+
| 需要 PostGIS。
 
|-
 
|-
 
| MySQL
 
| MySQL
| GEOS, GDAL
+
| 地球物理、GDAL
 
| 5.6.1+
 
| 5.6.1+
| [[../../db-api#mysql-spatial-limitations|<span class="std std-ref">Limited functionality</span>]].
+
| [[../../db-api#mysql-spatial-limitations|功能有限]]
 
|-
 
|-
| Oracle
+
| 甲骨文
| GEOS, GDAL
+
| 地球物理、GDAL
 
| 12.2+
 
| 12.2+
| XE not supported.
+
| 不支持 XE。
 
|-
 
|-
 
| SQLite
 
| SQLite
| GEOS, GDAL, PROJ.4, SpatiaLite
+
| GEOS、GDAL、PROJ.4、SpatiaLite
 
| 3.8.3+
 
| 3.8.3+
| Requires SpatiaLite 4.3+
+
| 需要 SpatiaLite 4.3+
 
|}
 
|}
  
See also [https://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS this comparison matrix] on the OSGeo Wiki for
+
另请参阅 OSGeo Wiki 上的 [https://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS 此比较矩阵] ,以了解 PostgreSQL/PostGIS/GEOS/GDAL 可能的组合。
PostgreSQL/PostGIS/GEOS/GDAL possible combinations.
 
  
  
第110行: 第98行:
 
<div id="geospatial-libraries" class="section">
 
<div id="geospatial-libraries" class="section">
  
=== Geospatial libraries ===
+
=== 地理空间图书馆 ===
  
 
<div class="toctree-wrapper compound">
 
<div class="toctree-wrapper compound">
  
* [[../geolibs|Installing Geospatial libraries]]
+
* [[../geolibs|安装地理空间库]]
  
  
第122行: 第110行:
 
<div id="database-installation" class="section">
 
<div id="database-installation" class="section">
  
=== Database installation ===
+
=== 数据库安装 ===
  
 
<div class="toctree-wrapper compound">
 
<div class="toctree-wrapper compound">
  
* [[../postgis|安装PostGIS]]
+
* [[../postgis|安装 PostGIS]]
* [[../spatialite|Installing SpatiaLite]]
+
* [[../spatialite|安装 SpatiaLite]]
  
  
第133行: 第121行:
  
 
</div>
 
</div>
<div id="databases-configuration" class="section">
+
<div id="setting-databases-configuration" class="section">
  
=== [[../../../../settings#std-setting-DATABASES|<code>DATABASES</code>]] configuration ===
+
=== :setting:`DATABASES` 配置 ===
  
Set the [[../../../../settings#std-setting-DATABASE-ENGINE|<code>ENGINE</code>]] setting to one of the [[../../db-api#spatial-backends|<span class="std std-ref">spatial
+
设置 [[#id5|:设置:`引擎 `]] 设置为其中之一[[../../db-api#spatial-backends|空间后端]] .
backends</span>]].
 
  
  
 
</div>
 
</div>
<div id="add-django-contrib-gis-to-installed-apps" class="section">
+
<div id="add-django-contrib-gis-to-setting-installed-apps" class="section">
  
=== Add <code>django.contrib.gis</code> to [[../../../../settings#std-setting-INSTALLED_APPS|<code>INSTALLED_APPS</code>]] ===
+
=== django.contrib.gis 添加到 :setting:`INSTALLED_APPS` ===
  
Like other Django contrib applications, you will ''only'' need to add
+
与其他 Django contrib 应用程序一样,您将 '''' 需要在您的设置中将 [[../../index#module-django.contrib|django.contrib.gis]] 添加到 [[#id9|:setting:`INSTALLED_APPS`]]。 这样就可以找到 <code>gis</code> 模板——如果不这样做,地理管理员或 KML 站点地图等功能将无法正常运行。
[[../../index#module-django.contrib|<code>django.contrib.gis</code>]] to [[../../../../settings#std-setting-INSTALLED_APPS|<code>INSTALLED_APPS</code>]] in your settings.
 
This is so that the <code>gis</code> templates can be located -- if not done, then
 
features such as the geographic admin or KML sitemaps will not function properly.
 
  
  
第157行: 第141行:
 
<div id="troubleshooting" class="section">
 
<div id="troubleshooting" class="section">
  
== 错误调试 ==
+
== 故障排除 ==
  
If you can't find the solution to your problem here then participate in the
+
如果您在这里找不到问题的解决方案,请参与社区! 你可以:
community! You can:
 
  
* Join the <code>#geodjango</code> IRC 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.
+
* 加入 Freenode 上的 <code>#geodjango</code> IRC 频道。 请耐心和礼貌——虽然您可能不会立即得到回复,但有人会在他们看到后立即尝试回答您的问题。
* Ask your question on the [https://groups.google.com/d/forum/geodjango GeoDjango] mailing list.
+
* [https://groups.google.com/d/forum/geodjango GeoDjango] 邮件列表上提问。
* File a ticket on the [https://code.djangoproject.com/newticket 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 &quot;GIS&quot;.
+
* 如果您认为存在错误,请在 [https://code.djangoproject.com/newticket Django trac] 上提交工单。 确保提供问题的完整描述、使用的版本,并将组件指定为“GIS”。
  
 
<div id="library-environment-settings" class="section">
 
<div id="library-environment-settings" class="section">
  
 
<span id="libsettings"></span>
 
<span id="libsettings"></span>
=== Library environment settings ===
+
=== 图书馆环境设置 ===
  
By far, the most common problem when installing GeoDjango is that the
+
到目前为止,安装 GeoDjango 时最常见的问题是无法定位外部共享库(例如,用于 GEOS 和 GDAL)。 [[#id35|1]] 通常,此问题的原因是操作系统不知道从源代码构建的库的安装目录。
external shared libraries (e.g., for GEOS and GDAL) cannot be located. [[#id27|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.
 
  
 
<div id="ld-library-path-environment-variable" class="section">
 
<div id="ld-library-path-environment-variable" class="section">
  
==== <code>LD_LIBRARY_PATH</code> environment variable ====
+
==== LD_LIBRARY_PATH 环境变量 ====
  
A user may set this environment variable to customize the library paths
+
用户可以设置这个环境变量来自定义他们想要使用的库路径。 从源代码构建的软件的典型库目录是 <code>/usr/local/lib</code>。 因此,<code>/usr/local/lib</code> 需要包含在 <code>LD_LIBRARY_PATH</code> 变量中。 例如,用户可以在他们的 bash 配置文件中放置以下内容:
they want to use. The typical library directory for software
 
built from source is <code>/usr/local/lib</code>. Thus, <code>/usr/local/lib</code> needs
 
to be included in the <code>LD_LIBRARY_PATH</code> variable. For example, the user
 
could place the following in their bash profile:
 
  
 
<div class="highlight-console notranslate">
 
<div class="highlight-console notranslate">
第194行: 第168行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>export LD_LIBRARY_PATH=/usr/local/lib</pre>
+
<syntaxhighlight lang="console">export LD_LIBRARY_PATH=/usr/local/lib</syntaxhighlight>
  
 
</div>
 
</div>
第203行: 第177行:
 
<div id="setting-system-library-path" class="section">
 
<div id="setting-system-library-path" class="section">
  
==== Setting system library path ====
+
==== 设置系统库路径 ====
  
On GNU/Linux systems, there is typically a file in <code>/etc/ld.so.conf</code>, which may include
+
GNU/Linux 系统上,通常在 <code>/etc/ld.so.conf</code> 中有一个文件,其中可能包含来自另一个目录中文件的附加路径,例如 <code>/etc/ld.so.conf.d</code>。 作为 root 用户,在 <code>ld.so.conf</code> 的新行中添加自定义库路径(如 <code>/usr/local/lib</code>)。 这是如何执行此操作的 ''one'' 示例:
additional paths from files in another directory, such as <code>/etc/ld.so.conf.d</code>.
 
As the root user, add the custom library path (like <code>/usr/local/lib</code>) on a
 
new line in <code>ld.so.conf</code>. This is ''one'' example of how to do so:
 
  
 
<div class="highlight-console notranslate">
 
<div class="highlight-console notranslate">
第214行: 第185行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>$ sudo echo /usr/local/lib &gt;&gt; /etc/ld.so.conf
+
<syntaxhighlight lang="console">$ sudo echo /usr/local/lib >> /etc/ld.so.conf
$ sudo ldconfig</pre>
+
$ sudo ldconfig</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
For OpenSolaris users, the system library path may be modified using the
+
对于 OpenSolaris 用户,可以使用 <code>crle</code> 实用程序修改系统库路径。 不带选项运行 <code>crle</code> 以查看当前配置并使用 <code>crle -l</code> 设置新的库路径。 修改系统库路径时要''非常''小心:
<code>crle</code> utility. Run <code>crle</code> with no options to see the current configuration
 
and use <code>crle -l</code> to set with the new library path. Be ''very'' careful when
 
modifying the system library path:
 
  
 
<div class="highlight-console notranslate">
 
<div class="highlight-console notranslate">
第229行: 第197行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre># crle -l $OLD_PATH:/usr/local/lib</pre>
+
<syntaxhighlight lang="console"># crle -l $OLD_PATH:/usr/local/lib</syntaxhighlight>
  
 
</div>
 
</div>
第239行: 第207行:
  
 
<span id="binutils"></span>
 
<span id="binutils"></span>
==== Install <code>binutils</code> ====
+
==== 安装 binutils ====
  
GeoDjango uses the <code>find_library</code> function (from the <code>ctypes.util</code> Python
+
GeoDjango 使用 <code>find_library</code> 函数(来自 <code>ctypes.util</code> Python 模块)来发现库。 <code>find_library</code> 例程使用一个名为 <code>objdump</code><code>binutils</code> 包的一部分)的程序来验证 GNU/Linux 系统上的共享库。 因此,如果 <code>binutils</code> 未安装在您的 Linux 系统上,那么即使您的库路径设置正确并且地理空间库已完美构建,Python 的 ctypes 也可能无法找到您的库。
module) to discover libraries. The <code>find_library</code> routine uses a program
 
called <code>objdump</code> (part of the <code>binutils</code> package) to verify a shared
 
library on GNU/Linux systems. Thus, if <code>binutils</code> 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 <code>binutils</code> package may be installed on Debian and Ubuntu systems using the
+
可以使用以下命令在 Debian 和 Ubuntu 系统上安装 <code>binutils</code> 软件包:
following command:
 
  
 
<div class="highlight-console notranslate">
 
<div class="highlight-console notranslate">
第255行: 第217行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>$ sudo apt-get install binutils</pre>
+
<syntaxhighlight lang="console">$ sudo apt-get install binutils</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
Similarly, on Red Hat and CentOS systems:
+
同样,在 Red Hat CentOS 系统上:
  
 
<div class="highlight-console notranslate">
 
<div class="highlight-console notranslate">
第266行: 第228行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>$ sudo yum install binutils</pre>
+
<syntaxhighlight lang="console">$ sudo yum install binutils</syntaxhighlight>
  
 
</div>
 
</div>
第279行: 第241行:
 
<div id="platform-specific-instructions" class="section">
 
<div id="platform-specific-instructions" class="section">
  
== Platform-specific instructions ==
+
== 特定于平台的说明 ==
  
 
<div id="macos" class="section">
 
<div id="macos" class="section">
  
<span id="id6"></span>
+
<span id="id14"></span>
 
=== macOS ===
 
=== macOS ===
  
Because of the variety of packaging systems available for macOS, users have
+
由于适用于 macOS 的打包系统多种多样,用户有多种不同的选项来安装 GeoDjango。 这些选项是:
several different options for installing GeoDjango. These options are:
 
  
* [[#postgresapp|<span class="std std-ref">Postgres.app</span>]] (easiest and recommended)
+
* [[#postgresapp|Postgres.app]](最简单和推荐)
* [[#homebrew|<span class="std std-ref">Homebrew</span>]]
+
* [[#homebrew|<span class="std std-ref">家酿</span>]]
* [[#kyngchaos|<span class="std std-ref">KyngChaos packages</span>]]
+
* [[#kyngchaos|<span class="std std-ref">KyngChaos 套餐</span>]]
* [[#fink|<span class="std std-ref">Fink</span>]]
+
* [[#fink|<span class="std std-ref">芬克</span>]]
* [[#macports|<span class="std std-ref">MacPorts</span>]]
+
* [[#macports|<span class="std std-ref">端口</span>]]
* [[../geolibs#build-from-source|<span class="std std-ref">Building from source</span>]]
+
* [[../geolibs#build-from-source|<span class="std std-ref">从源头构建</span>]]
  
This section also includes instructions for installing an upgraded version
+
本节还包括从 Python 软件基金会提供的包中安装 [[#macos-python|Python]] 升级版本的说明,但这不是必需的。
of [[#macos-python|<span class="std std-ref">Python</span>]] from packages provided by the Python Software
 
Foundation, however, this is not required.
 
  
 
<div id="python" class="section">
 
<div id="python" class="section">
  
 
<span id="macos-python"></span>
 
<span id="macos-python"></span>
==== Python ====
+
==== 蟒蛇 ====
  
Although macOS comes with Python installed, users can use [https://www.python.org/ftp/python/ framework
+
虽然 macOS 安装了 Python,但用户可以使用 Python Software Foundation 提供的 [https://www.python.org/ftp/python/ 框架安装程序] 。 使用安装程序的一个优势是 macOS Python 将保持“原始”供内部操作系统使用。
installers] provided by the Python Software Foundation. An advantage to
 
using the installer is that macOS's Python will remain &quot;pristine&quot; for internal
 
operating system use.
 
  
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
You will need to modify the <code>PATH</code> environment variable in your
+
您需要修改 <code>.profile</code> 文件中的 <code>PATH</code> 环境变量,以便在命令行输入 <code>python</code> 时使用新版本的 Python:
<code>.profile</code> file so that the new version of Python is used when
 
<code>python</code> is entered at the command-line:
 
  
 
<div class="highlight-console notranslate">
 
<div class="highlight-console notranslate">
第322行: 第276行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>export PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH</pre>
+
<syntaxhighlight lang="console">export PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH</syntaxhighlight>
  
 
</div>
 
</div>
第336行: 第290行:
 
==== Postgres.app ====
 
==== Postgres.app ====
  
[https://postgresapp.com/ Postgres.app] is a standalone PostgreSQL server
+
[https://postgresapp.com/ Postgres.app] 是一个独立的 PostgreSQL 服务器,包括 PostGIS 扩展。 您还需要使用 [[#homebrew|Homebrew]] 安装 <code>gdal</code> <code>libgeoip</code>
that includes the PostGIS extension. You will also need to install <code>gdal</code> and
 
<code>libgeoip</code> with [[#homebrew|<span class="std std-ref">Homebrew</span>]].
 
  
After installing Postgres.app, add the following to your <code>.bash_profile</code> so
+
安装 Postgres.app 后,将以下内容添加到 <code>.bash_profile</code> 中,以便您可以从命令行运行包的程序。 将 <code>X.Y</code> 替换为您安装的 Postgres.app 中的 PostgreSQL 版本:
you can run the package's programs from the command-line. Replace <code>X.Y</code> with
 
the version of PostgreSQL in the Postgres.app you installed:
 
  
 
<div class="highlight-bash notranslate">
 
<div class="highlight-bash notranslate">
第348行: 第298行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/X.Y/bin</pre>
+
<syntaxhighlight lang="bash">export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/X.Y/bin</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
You can check if the path is set up correctly by typing <code>which psql</code> at a
+
您可以通过在终端提示符下键入 <code>which psql</code> 来检查路径是否设置正确。
terminal prompt.
 
  
  
第360行: 第309行:
 
<div id="homebrew" class="section">
 
<div id="homebrew" class="section">
  
<span id="id9"></span>
+
<span id="id17"></span>
==== Homebrew ====
+
==== 家酿 ====
  
[https://brew.sh/ Homebrew] provides &quot;recipes&quot; for building binaries and packages from source.
+
[https://brew.sh/ Homebrew] 提供了从源代码构建二进制文件和包的“方法”。 它为运行 macOS 的 Macintosh 计算机上的 GeoDjango 先决条件提供了方法。 由于 Homebrew 仍然从源代码构建软件,因此需要 [https://developer.apple.com/xcode/ Xcode]
It provides recipes for the GeoDjango prerequisites on Macintosh computers
 
running macOS. Because Homebrew still builds the software from source, [https://developer.apple.com/xcode/ Xcode]
 
is required.
 
  
Summary:
+
概括:
  
 
<div class="highlight-console notranslate">
 
<div class="highlight-console notranslate">
第374行: 第320行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>$ brew install postgresql
+
<syntaxhighlight lang="console">$ brew install postgresql
 
$ brew install postgis
 
$ brew install postgis
 
$ brew install gdal
 
$ brew install gdal
$ brew install libgeoip</pre>
+
$ brew install libgeoip</syntaxhighlight>
  
 
</div>
 
</div>
第387行: 第333行:
  
 
<span id="kyngchaos"></span>
 
<span id="kyngchaos"></span>
==== KyngChaos packages ====
+
==== KyngChaos 套餐 ====
  
William Kyngesburye provides a number of [https://www.kyngchaos.com/software/frameworks geospatial library binary packages]
+
William Kyngesburye 提供了许多 [https://www.kyngchaos.com/software/frameworks 地理空间库二进制包] ,它们有助于在 macOS 上安装 GeoDjango,而无需从源代码编译它们。 然而,[https://developer.apple.com/xcode/ Xcode] 仍然需要编译 Python 数据库适配器 [[#psycopg2-kyngchaos|psycopg2]](用于 PostGIS)。
that help to get GeoDjango installed on macOS without compiling them from
 
source. However, [https://developer.apple.com/xcode/ Xcode] is still necessary for compiling the Python database
 
adapters [[#psycopg2-kyngchaos|<span class="std std-ref">psycopg2</span>]] (for PostGIS).
 
  
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
SpatiaLite users should consult the [[../spatialite#spatialite-macos|<span class="std std-ref">macOS-specific instructions</span>]] section
+
SpatiaLite 用户应在安装软件包后查阅 [[../spatialite#spatialite-macos|macOS 特定说明]] 部分以获取其他说明。
after installing the packages for additional instructions.
 
  
  
 
</div>
 
</div>
Download the framework packages for:
+
下载框架包:
  
 
* UnixImageIO
 
* UnixImageIO
* PROJ
+
* 项目
* GEOS
+
* 地球观测站
* SQLite3 (includes the SpatiaLite library)
+
* SQLite3(包括 SpatiaLite 库)
 
* GDAL
 
* GDAL
  
Install the packages in the order they are listed above, as the GDAL and SQLite
+
按照上面列出的顺序安装包,因为 GDAL SQLite 包需要在它们之前列出的包。
packages require the packages listed before them.
 
  
Afterwards, you can also install the KyngChaos binary packages for [https://www.kyngchaos.com/software/postgres PostgreSQL
+
之后,您还可以为 [https://www.kyngchaos.com/software/postgres PostgreSQL PostGIS] 安装 KyngChaos 二进制包。
and PostGIS].
 
  
After installing the binary packages, you'll want to add the following to
+
安装二进制包后,您需要将以下内容添加到 <code>.profile</code> 中,以便能够从命令行运行包程序:
your <code>.profile</code> to be able to run the package programs from the command-line:
 
  
 
<div class="highlight-console notranslate">
 
<div class="highlight-console notranslate">
第424行: 第363行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>export PATH=/Library/Frameworks/UnixImageIO.framework/Programs:$PATH
+
<syntaxhighlight lang="console">export PATH=/Library/Frameworks/UnixImageIO.framework/Programs:$PATH
 
export PATH=/Library/Frameworks/PROJ.framework/Programs:$PATH
 
export PATH=/Library/Frameworks/PROJ.framework/Programs:$PATH
 
export PATH=/Library/Frameworks/GEOS.framework/Programs:$PATH
 
export PATH=/Library/Frameworks/GEOS.framework/Programs:$PATH
 
export PATH=/Library/Frameworks/SQLite3.framework/Programs:$PATH
 
export PATH=/Library/Frameworks/SQLite3.framework/Programs:$PATH
 
export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH
 
export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH
export PATH=/usr/local/pgsql/bin:$PATH</pre>
+
export PATH=/usr/local/pgsql/bin:$PATH</syntaxhighlight>
  
 
</div>
 
</div>
第439行: 第378行:
 
===== psycopg2 =====
 
===== psycopg2 =====
  
After you've installed the KyngChaos binaries and modified your <code>PATH</code>, as
+
如上所述,安装 KyngChaos 二进制文件并修改 <code>PATH</code> 后,可以使用以下命令安装 <code>psycopg2</code>
described above, <code>psycopg2</code> may be installed using the following command:
 
  
 
<div class="highlight-console notranslate">
 
<div class="highlight-console notranslate">
第446行: 第384行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>$ python -m pip install psycopg2</pre>
+
<syntaxhighlight lang="console">$ python -m pip install psycopg2</syntaxhighlight>
  
 
</div>
 
</div>
第453行: 第391行:
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
If you don't have <code>pip</code>, follow the [[../../../../../topics/install#installing-official-release|<span class="std std-ref">installation instructions</span>]] to install it.
+
如果您没有<code>pip</code>,请按照[[../../../../../topics/install#installing-official-release|安装说明]]进行安装。
  
  
第463行: 第401行:
 
<div id="fink" class="section">
 
<div id="fink" class="section">
  
<span id="id13"></span>
+
<span id="id21"></span>
===== Fink =====
+
===== 芬克 =====
  
[https://schwehr.blogspot.com/ Kurt Schwehr] has been gracious enough to create GeoDjango packages for users
+
[https://schwehr.blogspot.com/ Kurt Schwehr] 慷慨地为 [http://www.finkproject.org/ Fink] 包系统的用户创建了 GeoDjango 包。 [http://pdb.finkproject.org/pdb/browse.php?summary=django-gis 有不同的包可用](从<code>django-gis</code>开始),取决于你想使用哪个版本的Python。
of the [http://www.finkproject.org/ Fink] package system. [http://pdb.finkproject.org/pdb/browse.php?summary=django-gis Different packages are available] (starting
 
with <code>django-gis</code>), depending on which version of Python you want to use.
 
  
  
第476行: 第412行:
 
<div id="macports" class="section">
 
<div id="macports" class="section">
  
<span id="id17"></span>
+
<span id="id25"></span>
==== MacPorts ====
+
==== 端口 ====
  
[https://www.macports.org/ MacPorts] may be used to install GeoDjango prerequisites on computers
+
[https://www.macports.org/ MacPorts] 可用于在运行 macOS 的计算机上安装 GeoDjango 先决条件。 由于 MacPorts 仍然从源代码构建软件,因此需要 [https://developer.apple.com/xcode/ Xcode]
running macOS. Because MacPorts still builds the software from source,
 
[https://developer.apple.com/xcode/ Xcode] is required.
 
  
Summary:
+
概括:
  
 
<div class="highlight-console notranslate">
 
<div class="highlight-console notranslate">
第489行: 第423行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>$ sudo port install postgresql93-server
+
<syntaxhighlight lang="console">$ sudo port install postgresql93-server
 
$ sudo port install geos
 
$ sudo port install geos
 
$ sudo port install proj
 
$ sudo port install proj
 
$ sudo port install postgis
 
$ sudo port install postgis
 
$ sudo port install gdal +geos
 
$ sudo port install gdal +geos
$ sudo port install libgeoip</pre>
+
$ sudo port install libgeoip</syntaxhighlight>
  
 
</div>
 
</div>
第501行: 第435行:
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
You will also have to modify the <code>PATH</code> in your <code>.profile</code> so
+
您还必须修改 <code>.profile</code> 中的 <code>PATH</code>,以便可以从命令行访问 MacPorts 程序:
that the MacPorts programs are accessible from the command-line:
 
  
 
<div class="highlight-console notranslate">
 
<div class="highlight-console notranslate">
第510行: 第443行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>export PATH=/opt/local/bin:/opt/local/lib/postgresql93/bin</pre>
+
<syntaxhighlight lang="console">export PATH=/opt/local/bin:/opt/local/lib/postgresql93/bin</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
In addition, add the <code>DYLD_FALLBACK_LIBRARY_PATH</code> setting so that
+
此外,添加 <code>DYLD_FALLBACK_LIBRARY_PATH</code> 设置,以便 Python 可以找到这些库:
the libraries can be found by Python:
 
  
 
<div class="highlight-console notranslate">
 
<div class="highlight-console notranslate">
第522行: 第454行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:/opt/local/lib/postgresql93</pre>
+
<syntaxhighlight lang="console">export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:/opt/local/lib/postgresql93</syntaxhighlight>
  
 
</div>
 
</div>
第535行: 第467行:
 
<div id="windows" class="section">
 
<div id="windows" class="section">
  
<span id="id19"></span>
+
<span id="id27"></span>
=== Windows ===
+
=== 窗户 ===
  
Proceed through the following sections sequentially in order to install
+
依次执行以下部分以在 Windows 上安装 GeoDjango。
GeoDjango on Windows.
 
  
<div id="id20" class="section">
+
<div id="id28" class="section">
  
==== Python ====
+
==== 蟒蛇 ====
  
[[../../../../../howto/windows|<span class="doc">Install Python</span>]].
+
[[../../../../../howto/windows|安装Python]]
  
  
第553行: 第484行:
 
==== PostgreSQL ====
 
==== PostgreSQL ====
  
First, download the latest [https://www.enterprisedb.com/downloads/postgres-postgresql-downloads PostgreSQL 9.x installer] from the
+
首先,从[https://www.enterprisedb.com EnterpriseDB]网站下载最新的[https://www.enterprisedb.com/downloads/postgres-postgresql-downloads PostgreSQL 9.x安装程序]。 下载后,运行安装程序,按照屏幕上的说明进行操作,并保留默认选项,除非您知道更改它们的后果。
[https://www.enterprisedb.com 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.
 
  
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
The PostgreSQL installer creates both a new Windows user to be the
+
PostgreSQL 安装程序会创建一个新的 Windows 用户作为“postgres 服务帐户”和一个 <code>postgres</code> 数据库超级用户。系统将提示您为这两个帐户设置密码 - 请务必记住它!
'postgres service account' and a <code>postgres</code> database superuser
 
You will be prompted once to set the password for both accounts --
 
make sure to remember it!
 
  
  
 
</div>
 
</div>
When the installer completes, it will ask to launch the Application Stack
+
安装程序完成后,它会要求在退出时启动应用程序堆栈生成器 (ASB) – 保持选中状态,因为需要安装 [[#postgisasb|PostGIS]]
Builder (ASB) on exit -- keep this checked, as it is necessary to
 
install [[#postgisasb|<span class="std std-ref">PostGIS</span>]].
 
  
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
If installed successfully, the PostgreSQL server will run in the
+
如果安装成功,每次系统作为 Windows 服务启动时,PostgreSQL 服务器都会在后台运行。 <span class="menuselection">PostgreSQL 9.x</span> 开始菜单组将创建并包含 ASB 和“SQL Shell”的快捷方式,它将启动 <code>psql</code> 命令窗口。
background each time the system as started as a Windows service.
 
A <span class="menuselection">PostgreSQL 9.x</span> start menu group will created
 
and contains shortcuts for the ASB as well as the 'SQL Shell',
 
which will launch a <code>psql</code> command window.
 
  
  
第590行: 第509行:
  
 
<span id="postgisasb"></span>
 
<span id="postgisasb"></span>
==== PostGIS ====
+
==== 地理信息系统 ====
  
From within the Application Stack Builder (to run outside of the installer,
+
Application Stack Builder 中(要在安装程序之外运行,<span class="menuselection">Start ‣ Programs ‣ PostgreSQL 9.x</span>),从下拉列表中选择 <span class="menuselection">PostgreSQL Database Server 9.x on port 5432</span>菜单。 接下来,展开 <span class="menuselection">Categories ‣ Spatial Extensions</span> 菜单树并选择 <span class="menuselection">PostGIS XY for PostgreSQL 9.x</span>
<span class="menuselection">Start ‣ Programs ‣ PostgreSQL 9.x</span>), select
 
<span class="menuselection">PostgreSQL Database Server 9.x on port 5432</span> from the drop down
 
menu. Next, expand the <span class="menuselection">Categories ‣ Spatial Extensions</span> menu
 
tree and select <span class="menuselection">PostGIS X.Y for PostgreSQL 9.x</span>.
 
  
After clicking next, you will be prompted to select your mirror, PostGIS
+
单击下一步后,系统将提示您选择镜像,将下载 PostGIS,并开始安装 PostGIS。 在安装过程中只选择默认选项(例如,不要取消选中创建默认 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).
 
  
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
You will be prompted to enter your <code>postgres</code> database superuser
+
系统将提示您在“数据库连接信息”对话框中输入 <code>postgres</code> 数据库超级用户密码。
password in the 'Database Connection Information' dialog.
 
  
  
第614行: 第525行:
  
 
</div>
 
</div>
<div id="id23" class="section">
+
<div id="id31" class="section">
  
 
==== psycopg2 ====
 
==== psycopg2 ====
  
The <code>psycopg2</code> Python module provides the interface between Python and the
+
<code>psycopg2</code> Python 模块提供了 Python PostgreSQL 数据库之间的接口。 下载适用于您的 Python 和 PostgreSQL 版本的最新 [http://www.stickpeople.com/projects/python/win-psycopg/ Windows 安装程序] ,并使用默认设置运行。 [[#id36|2]]
PostgreSQL database. Download the latest [http://www.stickpeople.com/projects/python/win-psycopg/ Windows installer] for your version
 
of Python and PostgreSQL and run using the default settings. [[#id28|2]]
 
  
  
第626行: 第535行:
 
<div id="osgeo4w" class="section">
 
<div id="osgeo4w" class="section">
  
<span id="id26"></span>
+
<span id="id34"></span>
 
==== OSGeo4W ====
 
==== OSGeo4W ====
  
The [https://trac.osgeo.org/osgeo4w/ OSGeo4W installer] helps to install the PROJ.4, GDAL, and GEOS libraries
+
[https://trac.osgeo.org/osgeo4w/ OSGeo4W 安装程序] 有助于安装 GeoDjango 所需的 PROJ.4、GDAL 和 GEOS 库。 首先,下载 [https://trac.osgeo.org/osgeo4w/ OSGeo4W 安装程序] ,并运行它。 选择<span class="menuselection">Express Web-GIS Install</span>,点击下一步。 在“选择包”列表中,确保选择了 GDAL; MapServer Apache 也默认启用,但 GeoDjango 不需要,可以安全地取消选中。 单击下一步后,软件包将自动下载并安装,之后您可以退出安装程序。
required by GeoDjango. First, download the [https://trac.osgeo.org/osgeo4w/ OSGeo4W installer], and run it.
 
Select <span class="menuselection">Express Web-GIS Install</span> 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.
 
  
  
第641行: 第544行:
 
<div id="modify-windows-environment" class="section">
 
<div id="modify-windows-environment" class="section">
  
==== Modify Windows environment ====
+
==== 修改Windows环境 ====
  
In order to use GeoDjango, you will need to add your Python and OSGeo4W
+
为了使用 GeoDjango,您需要将 Python OSGeo4W 目录添加到 Windows 系统 <code>Path</code>,并创建 <code>GDAL_DATA</code> <code>PROJ_LIB</code> 环境变量。 下面的命令集,可以用 <code>cmd.exe</code> 执行,将设置它:
directories to your Windows system <code>Path</code>, as well as create <code>GDAL_DATA</code>
 
and <code>PROJ_LIB</code> environment variables. The following set of commands,
 
executable with <code>cmd.exe</code>, will set this up:
 
  
 
<div class="highlight-bat notranslate">
 
<div class="highlight-bat notranslate">
第652行: 第552行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>set OSGEO4W_ROOT=C:\OSGeo4W
+
<syntaxhighlight lang="bat">set OSGEO4W_ROOT=C:\OSGeo4W
 
set PYTHON_ROOT=C:\Python3X
 
set PYTHON_ROOT=C:\Python3X
 
set GDAL_DATA=%OSGEO4W_ROOT%\share\gdal
 
set GDAL_DATA=%OSGEO4W_ROOT%\share\gdal
 
set PROJ_LIB=%OSGEO4W_ROOT%\share\proj
 
set PROJ_LIB=%OSGEO4W_ROOT%\share\proj
 
set PATH=%PATH%;%PYTHON_ROOT%;%OSGEO4W_ROOT%\bin
 
set PATH=%PATH%;%PYTHON_ROOT%;%OSGEO4W_ROOT%\bin
reg ADD &quot;HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment&quot; /v Path /t REG_EXPAND_SZ /f /d &quot;%PATH%&quot;
+
reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /f /d "%PATH%"
reg ADD &quot;HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment&quot; /v GDAL_DATA /t REG_EXPAND_SZ /f /d &quot;%GDAL_DATA%&quot;
+
reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v GDAL_DATA /t REG_EXPAND_SZ /f /d "%GDAL_DATA%"
reg ADD &quot;HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment&quot; /v PROJ_LIB /t REG_EXPAND_SZ /f /d &quot;%PROJ_LIB%&quot;</pre>
+
reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROJ_LIB /t REG_EXPAND_SZ /f /d "%PROJ_LIB%"</syntaxhighlight>
  
 
</div>
 
</div>
第666行: 第566行:
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
Administrator privileges are required to execute these commands.
+
执行这些命令需要管理员权限。 为此,请使用命令创建 <code>bat</code> 脚本,右键单击它,然后选择 <span class="menuselection"> 以管理员身份运行 </span>。 您需要注销并重新登录才能使设置生效。
To do this, create a <code>bat</code> script with the commands, right-click it, and
 
select <span class="menuselection">Run as administrator</span>. You need to log out and log
 
back in again for the settings to take effect.
 
  
  
第677行: 第574行:
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
If you customized the Python or OSGeo4W installation directories,
+
如果您自定义了 Python OSGeo4W 安装目录,则需要相应地修改 <code>OSGEO4W_ROOT</code> /<code>PYTHON_ROOT</code> 变量。
then you will need to modify the <code>OSGEO4W_ROOT</code> and/or <code>PYTHON_ROOT</code>
 
variables accordingly.
 
  
  
第689行: 第584行:
 
<div id="install-django-and-set-up-database" class="section">
 
<div id="install-django-and-set-up-database" class="section">
  
==== 安装Django并设置数据库 ====
+
==== 安装 Django 并设置数据库 ====
 +
 
 +
最后, [[../../../../../topics/install#installing-official-release|在你的系统上安装 Django]]。
  
Finally, [[../../../../../topics/install#installing-official-release|<span class="std std-ref">install Django</span>]] on your system.
+
脚注
  
Footnotes
+
; <span class="brackets">[[#id13|1]]</span>
 +
: GeoDjango 使用 <code>ctypes.util</code> 中的 <code>find_library()</code> 例程来定位共享库。
 +
; <span class="brackets">[[#id32|2]]</span>
 +
: <code>psycopg2</code> Windows 安装程序由 [http://www.stickpeople.com/projects/python/win-psycopg/ Jason Erickson] 打包和维护。
  
; <span class="brackets">[[#id5|1]]</span>
 
: GeoDjango uses the <code>find_library()</code> routine from <code>ctypes.util</code> to locate shared libraries.
 
; <span class="brackets">[[#id24|2]]</span>
 
: The <code>psycopg2</code> Windows installers are packaged and maintained by [http://www.stickpeople.com/projects/python/win-psycopg/ Jason Erickson].
 
  
 +
</div>
  
 
</div>
 
</div>
第706行: 第603行:
  
 
</div>
 
</div>
 +
<div class="clearer">
 +
 +
  
 
</div>
 
</div>
  
[[Category:Django 3.0.x 中文文档]]
+
[[Category:Django 3.0.x 文档]]

2021年10月31日 (日) 04:09的最新版本

GeoDjango 安装

概览

一般来说,GeoDjango 安装需要:

  1. Python 和 Django
  2. 空间数据库
  3. 安装地理空间库

以下各节提供了每个要求和安装说明的详细信息。 此外,平台特定的说明可用于:

使用源

因为 GeoDjango 利用了最新的开源地理空间软件技术,所以需要最新版本的库。 如果二进制包不适用于您的平台,则可能需要从源代码安装。 从源代码编译库时,请严格按照说明进行操作,特别是如果您是初学者。


要求

Python 和 Django

由于GeoDjango 包含在Django 中,详细安装方法请参考Django 的安装说明


空间数据库

目前支持的空间数据库有 PostgreSQL(带有 PostGIS)、MySQL(主要带有 MyISAM 引擎)、Oracle 和 SQLite(带有 SpatiaLite)。

笔记

推荐使用 PostGIS,因为它是最成熟、功能最丰富的开源空间数据库。


GeoDjango 安装所需的地理空间库取决于所使用的空间数据库。 下面列出了每个支持的数据库后端的库要求、支持的版本和任何注意事项:

数据库 图书馆要求 支持的版本 笔记
PostgreSQL GEOS、GDAL、PROJ.4、PostGIS 9.5+ 需要 PostGIS。
MySQL 地球物理、GDAL 5.6.1+ 功能有限
甲骨文 地球物理、GDAL 12.2+ 不支持 XE。
SQLite GEOS、GDAL、PROJ.4、SpatiaLite 3.8.3+ 需要 SpatiaLite 4.3+

另请参阅 OSGeo Wiki 上的 此比较矩阵 ,以了解 PostgreSQL/PostGIS/GEOS/GDAL 可能的组合。


安装

地理空间图书馆

:setting:`DATABASES` 配置

设置 :设置:`引擎 ` 设置为其中之一空间后端 .


将 django.contrib.gis 添加到 :setting:`INSTALLED_APPS`

与其他 Django contrib 应用程序一样,您将 需要在您的设置中将 django.contrib.gis 添加到 :setting:`INSTALLED_APPS`。 这样就可以找到 gis 模板——如果不这样做,地理管理员或 KML 站点地图等功能将无法正常运行。


故障排除

如果您在这里找不到问题的解决方案,请参与社区! 你可以:

  • 加入 Freenode 上的 #geodjango IRC 频道。 请耐心和礼貌——虽然您可能不会立即得到回复,但有人会在他们看到后立即尝试回答您的问题。
  • GeoDjango 邮件列表上提问。
  • 如果您认为存在错误,请在 Django trac 上提交工单。 确保提供问题的完整描述、使用的版本,并将组件指定为“GIS”。

图书馆环境设置

到目前为止,安装 GeoDjango 时最常见的问题是无法定位外部共享库(例如,用于 GEOS 和 GDAL)。 1 通常,此问题的原因是操作系统不知道从源代码构建的库的安装目录。

通常,可以通过设置环境变量或通过为整个系统配置库路径来基于每个用户设置库路径。

LD_LIBRARY_PATH 环境变量

用户可以设置这个环境变量来自定义他们想要使用的库路径。 从源代码构建的软件的典型库目录是 /usr/local/lib。 因此,/usr/local/lib 需要包含在 LD_LIBRARY_PATH 变量中。 例如,用户可以在他们的 bash 配置文件中放置以下内容:

export LD_LIBRARY_PATH=/usr/local/lib

设置系统库路径

在 GNU/Linux 系统上,通常在 /etc/ld.so.conf 中有一个文件,其中可能包含来自另一个目录中文件的附加路径,例如 /etc/ld.so.conf.d。 作为 root 用户,在 ld.so.conf 的新行中添加自定义库路径(如 /usr/local/lib)。 这是如何执行此操作的 one 示例:

$ sudo echo /usr/local/lib >> /etc/ld.so.conf
$ sudo ldconfig

对于 OpenSolaris 用户,可以使用 crle 实用程序修改系统库路径。 不带选项运行 crle 以查看当前配置并使用 crle -l 设置新的库路径。 修改系统库路径时要非常小心:

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

安装 binutils

GeoDjango 使用 find_library 函数(来自 ctypes.util Python 模块)来发现库。 find_library 例程使用一个名为 objdumpbinutils 包的一部分)的程序来验证 GNU/Linux 系统上的共享库。 因此,如果 binutils 未安装在您的 Linux 系统上,那么即使您的库路径设置正确并且地理空间库已完美构建,Python 的 ctypes 也可能无法找到您的库。

可以使用以下命令在 Debian 和 Ubuntu 系统上安装 binutils 软件包:

$ sudo apt-get install binutils

同样,在 Red Hat 和 CentOS 系统上:

$ sudo yum install binutils

特定于平台的说明

macOS

由于适用于 macOS 的打包系统多种多样,用户有多种不同的选项来安装 GeoDjango。 这些选项是:

本节还包括从 Python 软件基金会提供的包中安装 Python 升级版本的说明,但这不是必需的。

蟒蛇

虽然 macOS 安装了 Python,但用户可以使用 Python Software Foundation 提供的 框架安装程序 。 使用安装程序的一个优势是 macOS 的 Python 将保持“原始”供内部操作系统使用。

笔记

您需要修改 .profile 文件中的 PATH 环境变量,以便在命令行输入 python 时使用新版本的 Python:

export PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH

Postgres.app

Postgres.app 是一个独立的 PostgreSQL 服务器,包括 PostGIS 扩展。 您还需要使用 Homebrew 安装 gdallibgeoip

安装 Postgres.app 后,将以下内容添加到 .bash_profile 中,以便您可以从命令行运行包的程序。 将 X.Y 替换为您安装的 Postgres.app 中的 PostgreSQL 版本:

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

您可以通过在终端提示符下键入 which psql 来检查路径是否设置正确。


家酿

Homebrew 提供了从源代码构建二进制文件和包的“方法”。 它为运行 macOS 的 Macintosh 计算机上的 GeoDjango 先决条件提供了方法。 由于 Homebrew 仍然从源代码构建软件,因此需要 Xcode

概括:

$ brew install postgresql
$ brew install postgis
$ brew install gdal
$ brew install libgeoip

KyngChaos 套餐

William Kyngesburye 提供了许多 地理空间库二进制包 ,它们有助于在 macOS 上安装 GeoDjango,而无需从源代码编译它们。 然而,Xcode 仍然需要编译 Python 数据库适配器 psycopg2(用于 PostGIS)。

笔记

SpatiaLite 用户应在安装软件包后查阅 macOS 特定说明 部分以获取其他说明。


下载框架包:

  • UnixImageIO
  • 项目
  • 地球观测站
  • SQLite3(包括 SpatiaLite 库)
  • GDAL

按照上面列出的顺序安装包,因为 GDAL 和 SQLite 包需要在它们之前列出的包。

之后,您还可以为 PostgreSQL 和 PostGIS 安装 KyngChaos 二进制包。

安装二进制包后,您需要将以下内容添加到 .profile 中,以便能够从命令行运行包程序:

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

psycopg2

如上所述,安装 KyngChaos 二进制文件并修改 PATH 后,可以使用以下命令安装 psycopg2

$ python -m pip install psycopg2

笔记

如果您没有pip,请按照安装说明进行安装。


芬克

Kurt Schwehr 慷慨地为 Fink 包系统的用户创建了 GeoDjango 包。 有不同的包可用(从django-gis开始),取决于你想使用哪个版本的Python。


端口

MacPorts 可用于在运行 macOS 的计算机上安装 GeoDjango 先决条件。 由于 MacPorts 仍然从源代码构建软件,因此需要 Xcode

概括:

$ 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

笔记

您还必须修改 .profile 中的 PATH,以便可以从命令行访问 MacPorts 程序:

export PATH=/opt/local/bin:/opt/local/lib/postgresql93/bin

此外,添加 DYLD_FALLBACK_LIBRARY_PATH 设置,以便 Python 可以找到这些库:

export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:/opt/local/lib/postgresql93

窗户

依次执行以下部分以在 Windows 上安装 GeoDjango。

蟒蛇

安装Python


PostgreSQL

首先,从EnterpriseDB网站下载最新的PostgreSQL 9.x安装程序。 下载后,运行安装程序,按照屏幕上的说明进行操作,并保留默认选项,除非您知道更改它们的后果。

笔记

PostgreSQL 安装程序会创建一个新的 Windows 用户作为“postgres 服务帐户”和一个 postgres 数据库超级用户。系统将提示您为这两个帐户设置密码 - 请务必记住它!


安装程序完成后,它会要求在退出时启动应用程序堆栈生成器 (ASB) – 保持选中状态,因为需要安装 PostGIS

笔记

如果安装成功,每次系统作为 Windows 服务启动时,PostgreSQL 服务器都会在后台运行。 PostgreSQL 9.x 开始菜单组将创建并包含 ASB 和“SQL Shell”的快捷方式,它将启动 psql 命令窗口。


地理信息系统

在 Application Stack Builder 中(要在安装程序之外运行,Start ‣ Programs ‣ PostgreSQL 9.x),从下拉列表中选择 PostgreSQL Database Server 9.x on port 5432菜单。 接下来,展开 Categories ‣ Spatial Extensions 菜单树并选择 PostGIS XY for PostgreSQL 9.x

单击下一步后,系统将提示您选择镜像,将下载 PostGIS,并开始安装 PostGIS。 在安装过程中只选择默认选项(例如,不要取消选中创建默认 PostGIS 数据库的选项)。

笔记

系统将提示您在“数据库连接信息”对话框中输入 postgres 数据库超级用户密码。


psycopg2

psycopg2 Python 模块提供了 Python 和 PostgreSQL 数据库之间的接口。 下载适用于您的 Python 和 PostgreSQL 版本的最新 Windows 安装程序 ,并使用默认设置运行。 2


OSGeo4W

OSGeo4W 安装程序 有助于安装 GeoDjango 所需的 PROJ.4、GDAL 和 GEOS 库。 首先,下载 OSGeo4W 安装程序 ,并运行它。 选择Express Web-GIS Install,点击下一步。 在“选择包”列表中,确保选择了 GDAL; MapServer 和 Apache 也默认启用,但 GeoDjango 不需要,可以安全地取消选中。 单击下一步后,软件包将自动下载并安装,之后您可以退出安装程序。


修改Windows环境

为了使用 GeoDjango,您需要将 Python 和 OSGeo4W 目录添加到 Windows 系统 Path,并创建 GDAL_DATAPROJ_LIB 环境变量。 下面的命令集,可以用 cmd.exe 执行,将设置它:

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

笔记

执行这些命令需要管理员权限。 为此,请使用命令创建 bat 脚本,右键单击它,然后选择 以管理员身份运行 。 您需要注销并重新登录才能使设置生效。


笔记

如果您自定义了 Python 或 OSGeo4W 安装目录,则需要相应地修改 OSGEO4W_ROOT 和/或 PYTHON_ROOT 变量。


安装 Django 并设置数据库

最后, 在你的系统上安装 Django

脚注

1
GeoDjango 使用 ctypes.util 中的 find_library() 例程来定位共享库。
2
psycopg2 Windows 安装程序由 Jason Erickson 打包和维护。