“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 | + | = GeoDjango 安装 = |
<div id="overview" class="section"> | <div id="overview" class="section"> | ||
− | == | + | == 概览 == |
− | + | 一般来说,GeoDjango 安装需要: | |
− | # [[#django|<span class="std std-ref">Python | + | # [[#django|<span class="std std-ref">Python 和 Django</span>]] |
− | # [[#spatial-database|<span class="std std-ref"> | + | # [[#spatial-database|<span class="std std-ref">空间数据库</span>]] |
− | # [[../geolibs|<span class="doc"> | + | # [[../geolibs|<span class="doc">安装地理空间库</span>]] |
− | + | 以下各节提供了每个要求和安装说明的详细信息。 此外,平台特定的说明可用于: | |
− | |||
− | |||
* [[#macos|<span class="std std-ref">macOS</span>]] | * [[#macos|<span class="std std-ref">macOS</span>]] | ||
− | * [[#windows|<span class="std std-ref"> | + | * [[#windows|<span class="std std-ref">窗户</span>]] |
<div class="admonition-use-the-source admonition"> | <div class="admonition-use-the-source admonition"> | ||
− | + | 使用源 | |
− | + | 因为 GeoDjango 利用了最新的开源地理空间软件技术,所以需要最新版本的库。 如果二进制包不适用于您的平台,则可能需要从源代码安装。 从源代码编译库时,请严格按照说明进行操作,特别是如果您是初学者。 | |
− | |||
− | |||
− | |||
− | |||
第36行: | 第31行: | ||
<div id="requirements" class="section"> | <div id="requirements" class="section"> | ||
− | == | + | == 要求 == |
<div id="python-and-django" class="section"> | <div id="python-and-django" class="section"> | ||
<span id="django"></span> | <span id="django"></span> | ||
− | === Python | + | === Python 和 Django === |
− | + | 由于GeoDjango 包含在Django 中,详细安装方法请参考Django 的[[../../../../../topics/install#installing-official-release|安装说明]]。 | |
− | [[../../../../../topics/install#installing-official-release| | ||
− | |||
第52行: | 第45行: | ||
<span id="id1"></span> | <span id="id1"></span> | ||
− | === | + | === 空间数据库 === |
− | + | 目前支持的空间数据库有 PostgreSQL(带有 PostGIS)、MySQL(主要带有 MyISAM 引擎)、Oracle 和 SQLite(带有 SpatiaLite)。 | |
− | |||
<div class="admonition note"> | <div class="admonition note"> | ||
− | + | 笔记 | |
− | + | 推荐使用 PostGIS,因为它是最成熟、功能最丰富的开源空间数据库。 | |
− | |||
</div> | </div> | ||
− | + | GeoDjango 安装所需的地理空间库取决于所使用的空间数据库。 下面列出了每个支持的数据库后端的库要求、支持的版本和任何注意事项: | |
− | |||
− | |||
{| | {| | ||
!width="15%"| 数据库 | !width="15%"| 数据库 | ||
− | !width="24%"| | + | !width="24%"| 图书馆要求 |
− | !width="15%"| | + | !width="15%"| 支持的版本 |
− | !width="46%"| | + | !width="46%"| 笔记 |
|- | |- | ||
| PostgreSQL | | PostgreSQL | ||
− | | | + | | GEOS、GDAL、PROJ.4、PostGIS |
| 9.5+ | | 9.5+ | ||
− | | | + | | 需要 PostGIS。 |
|- | |- | ||
| MySQL | | MySQL | ||
− | | | + | | 地球物理、GDAL |
| 5.6.1+ | | 5.6.1+ | ||
− | | [[../../db-api#mysql-spatial-limitations| | + | | [[../../db-api#mysql-spatial-limitations|功能有限]]。 |
|- | |- | ||
− | | | + | | 甲骨文 |
− | | | + | | 地球物理、GDAL |
| 12.2+ | | 12.2+ | ||
− | | | + | | 不支持 XE。 |
|- | |- | ||
| SQLite | | SQLite | ||
− | | | + | | GEOS、GDAL、PROJ.4、SpatiaLite |
| 3.8.3+ | | 3.8.3+ | ||
− | | | + | | 需要 SpatiaLite 4.3+ |
|} | |} | ||
− | + | 另请参阅 OSGeo Wiki 上的 [https://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS 此比较矩阵] ,以了解 PostgreSQL/PostGIS/GEOS/GDAL 可能的组合。 | |
− | PostgreSQL/PostGIS/GEOS/GDAL | ||
第110行: | 第98行: | ||
<div id="geospatial-libraries" class="section"> | <div id="geospatial-libraries" class="section"> | ||
− | === | + | === 地理空间图书馆 === |
<div class="toctree-wrapper compound"> | <div class="toctree-wrapper compound"> | ||
− | * [[../geolibs| | + | * [[../geolibs|安装地理空间库]] |
第122行: | 第110行: | ||
<div id="database-installation" class="section"> | <div id="database-installation" class="section"> | ||
− | === | + | === 数据库安装 === |
<div class="toctree-wrapper compound"> | <div class="toctree-wrapper compound"> | ||
− | * [[../postgis| | + | * [[../postgis|安装 PostGIS]] |
− | * [[../spatialite| | + | * [[../spatialite|安装 SpatiaLite]] |
第133行: | 第121行: | ||
</div> | </div> | ||
− | <div id="databases-configuration" class="section"> | + | <div id="setting-databases-configuration" class="section"> |
− | === | + | === :setting:`DATABASES` 配置 === |
− | + | 设置 [[#id5|:设置:`引擎 `]] 设置为其中之一[[../../db-api#spatial-backends|空间后端]] . | |
− | |||
</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"> |
− | === | + | === 将 django.contrib.gis 添加到 :setting:`INSTALLED_APPS` === |
− | + | 与其他 Django contrib 应用程序一样,您将 ''仅'' 需要在您的设置中将 [[../../index#module-django.contrib|django.contrib.gis]] 添加到 [[#id9|:setting:`INSTALLED_APPS`]]。 这样就可以找到 <code>gis</code> 模板——如果不这样做,地理管理员或 KML 站点地图等功能将无法正常运行。 | |
− | [[../../index#module-django.contrib| | ||
− | |||
− | |||
第157行: | 第141行: | ||
<div id="troubleshooting" class="section"> | <div id="troubleshooting" class="section"> | ||
− | == | + | == 故障排除 == |
− | + | 如果您在这里找不到问题的解决方案,请参与社区! 你可以: | |
− | |||
− | * | + | * 加入 Freenode 上的 <code>#geodjango</code> IRC 频道。 请耐心和礼貌——虽然您可能不会立即得到回复,但有人会在他们看到后立即尝试回答您的问题。 |
− | * | + | * 在 [https://groups.google.com/d/forum/geodjango GeoDjango] 邮件列表上提问。 |
− | * | + | * 如果您认为存在错误,请在 [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> | ||
− | === | + | === 图书馆环境设置 === |
− | + | 到目前为止,安装 GeoDjango 时最常见的问题是无法定位外部共享库(例如,用于 GEOS 和 GDAL)。 [[#id35|1]] 通常,此问题的原因是操作系统不知道从源代码构建的库的安装目录。 | |
− | |||
− | |||
− | |||
− | + | 通常,可以通过设置环境变量或通过为整个系统配置库路径来基于每个用户设置库路径。 | |
− | |||
− | |||
<div id="ld-library-path-environment-variable" class="section"> | <div id="ld-library-path-environment-variable" class="section"> | ||
− | ==== | + | ==== LD_LIBRARY_PATH 环境变量 ==== |
− | + | 用户可以设置这个环境变量来自定义他们想要使用的库路径。 从源代码构建的软件的典型库目录是 <code>/usr/local/lib</code>。 因此,<code>/usr/local/lib</code> 需要包含在 <code>LD_LIBRARY_PATH</code> 变量中。 例如,用户可以在他们的 bash 配置文件中放置以下内容: | |
− | |||
− | |||
− | |||
− | |||
<div class="highlight-console notranslate"> | <div class="highlight-console notranslate"> | ||
第194行: | 第168行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <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"> | ||
− | ==== | + | ==== 设置系统库路径 ==== |
− | + | 在 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'' 示例: | |
− | |||
− | |||
− | |||
<div class="highlight-console notranslate"> | <div class="highlight-console notranslate"> | ||
第214行: | 第185行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <syntaxhighlight lang="console">$ sudo echo /usr/local/lib >> /etc/ld.so.conf |
− | $ sudo ldconfig</ | + | $ sudo ldconfig</syntaxhighlight> |
</div> | </div> | ||
</div> | </div> | ||
− | + | 对于 OpenSolaris 用户,可以使用 <code>crle</code> 实用程序修改系统库路径。 不带选项运行 <code>crle</code> 以查看当前配置并使用 <code>crle -l</code> 设置新的库路径。 修改系统库路径时要''非常''小心: | |
− | <code>crle</code> | ||
− | |||
− | |||
<div class="highlight-console notranslate"> | <div class="highlight-console notranslate"> | ||
第229行: | 第197行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <syntaxhighlight lang="console"># crle -l $OLD_PATH:/usr/local/lib</syntaxhighlight> |
</div> | </div> | ||
第239行: | 第207行: | ||
<span id="binutils"></span> | <span id="binutils"></span> | ||
− | ==== | + | ==== 安装 binutils ==== |
− | GeoDjango | + | 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 也可能无法找到您的库。 |
− | |||
− | |||
− | |||
− | Linux | ||
− | |||
− | + | 可以使用以下命令在 Debian 和 Ubuntu 系统上安装 <code>binutils</code> 软件包: | |
− | |||
<div class="highlight-console notranslate"> | <div class="highlight-console notranslate"> | ||
第255行: | 第217行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <syntaxhighlight lang="console">$ sudo apt-get install binutils</syntaxhighlight> |
</div> | </div> | ||
</div> | </div> | ||
− | + | 同样,在 Red Hat 和 CentOS 系统上: | |
<div class="highlight-console notranslate"> | <div class="highlight-console notranslate"> | ||
第266行: | 第228行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <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"> | ||
− | == | + | == 特定于平台的说明 == |
<div id="macos" class="section"> | <div id="macos" class="section"> | ||
− | <span id=" | + | <span id="id14"></span> |
=== macOS === | === macOS === | ||
− | + | 由于适用于 macOS 的打包系统多种多样,用户有多种不同的选项来安装 GeoDjango。 这些选项是: | |
− | |||
− | * [[#postgresapp| | + | * [[#postgresapp|Postgres.app]](最简单和推荐) |
− | * [[#homebrew|<span class="std std-ref"> | + | * [[#homebrew|<span class="std std-ref">家酿</span>]] |
− | * [[#kyngchaos|<span class="std std-ref">KyngChaos | + | * [[#kyngchaos|<span class="std std-ref">KyngChaos 套餐</span>]] |
− | * [[#fink|<span class="std std-ref"> | + | * [[#fink|<span class="std std-ref">芬克</span>]] |
− | * [[#macports|<span class="std std-ref"> | + | * [[#macports|<span class="std std-ref">端口</span>]] |
− | * [[../geolibs#build-from-source|<span class="std std-ref"> | + | * [[../geolibs#build-from-source|<span class="std std-ref">从源头构建</span>]] |
− | + | 本节还包括从 Python 软件基金会提供的包中安装 [[#macos-python|Python]] 升级版本的说明,但这不是必需的。 | |
− | |||
− | |||
<div id="python" class="section"> | <div id="python" class="section"> | ||
<span id="macos-python"></span> | <span id="macos-python"></span> | ||
− | ==== | + | ==== 蟒蛇 ==== |
− | + | 虽然 macOS 安装了 Python,但用户可以使用 Python Software Foundation 提供的 [https://www.python.org/ftp/python/ 框架安装程序] 。 使用安装程序的一个优势是 macOS 的 Python 将保持“原始”供内部操作系统使用。 | |
− | |||
− | |||
− | |||
<div class="admonition note"> | <div class="admonition note"> | ||
− | + | 笔记 | |
− | + | 您需要修改 <code>.profile</code> 文件中的 <code>PATH</code> 环境变量,以便在命令行输入 <code>python</code> 时使用新版本的 Python: | |
− | <code> | ||
− | <code>python</code> | ||
<div class="highlight-console notranslate"> | <div class="highlight-console notranslate"> | ||
第322行: | 第276行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <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] | + | [https://postgresapp.com/ Postgres.app] 是一个独立的 PostgreSQL 服务器,包括 PostGIS 扩展。 您还需要使用 [[#homebrew|Homebrew]] 安装 <code>gdal</code> 和 <code>libgeoip</code>。 |
− | |||
− | <code>libgeoip</code> | ||
− | + | 安装 Postgres.app 后,将以下内容添加到 <code>.bash_profile</code> 中,以便您可以从命令行运行包的程序。 将 <code>X.Y</code> 替换为您安装的 Postgres.app 中的 PostgreSQL 版本: | |
− | |||
− | |||
<div class="highlight-bash notranslate"> | <div class="highlight-bash notranslate"> | ||
第348行: | 第298行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <syntaxhighlight lang="bash">export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/X.Y/bin</syntaxhighlight> |
</div> | </div> | ||
</div> | </div> | ||
− | + | 您可以通过在终端提示符下键入 <code>which psql</code> 来检查路径是否设置正确。 | |
− | |||
第360行: | 第309行: | ||
<div id="homebrew" class="section"> | <div id="homebrew" class="section"> | ||
− | <span id=" | + | <span id="id17"></span> |
− | ==== | + | ==== 家酿 ==== |
− | [https://brew.sh/ Homebrew] | + | [https://brew.sh/ Homebrew] 提供了从源代码构建二进制文件和包的“方法”。 它为运行 macOS 的 Macintosh 计算机上的 GeoDjango 先决条件提供了方法。 由于 Homebrew 仍然从源代码构建软件,因此需要 [https://developer.apple.com/xcode/ Xcode]。 |
− | |||
− | |||
− | |||
− | + | 概括: | |
<div class="highlight-console notranslate"> | <div class="highlight-console notranslate"> | ||
第374行: | 第320行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <syntaxhighlight lang="console">$ brew install postgresql |
$ brew install postgis | $ brew install postgis | ||
$ brew install gdal | $ brew install gdal | ||
− | $ brew install libgeoip</ | + | $ brew install libgeoip</syntaxhighlight> |
</div> | </div> | ||
第387行: | 第333行: | ||
<span id="kyngchaos"></span> | <span id="kyngchaos"></span> | ||
− | ==== KyngChaos | + | ==== KyngChaos 套餐 ==== |
− | William Kyngesburye | + | William Kyngesburye 提供了许多 [https://www.kyngchaos.com/software/frameworks 地理空间库二进制包] ,它们有助于在 macOS 上安装 GeoDjango,而无需从源代码编译它们。 然而,[https://developer.apple.com/xcode/ Xcode] 仍然需要编译 Python 数据库适配器 [[#psycopg2-kyngchaos|psycopg2]](用于 PostGIS)。 |
− | |||
− | |||
− | |||
<div class="admonition note"> | <div class="admonition note"> | ||
− | + | 笔记 | |
− | SpatiaLite | + | SpatiaLite 用户应在安装软件包后查阅 [[../spatialite#spatialite-macos|macOS 特定说明]] 部分以获取其他说明。 |
− | |||
</div> | </div> | ||
− | + | 下载框架包: | |
* UnixImageIO | * UnixImageIO | ||
− | * | + | * 项目 |
− | * | + | * 地球观测站 |
− | * | + | * SQLite3(包括 SpatiaLite 库) |
* GDAL | * GDAL | ||
− | + | 按照上面列出的顺序安装包,因为 GDAL 和 SQLite 包需要在它们之前列出的包。 | |
− | |||
− | + | 之后,您还可以为 [https://www.kyngchaos.com/software/postgres PostgreSQL 和 PostGIS] 安装 KyngChaos 二进制包。 | |
− | |||
− | + | 安装二进制包后,您需要将以下内容添加到 <code>.profile</code> 中,以便能够从命令行运行包程序: | |
− | |||
<div class="highlight-console notranslate"> | <div class="highlight-console notranslate"> | ||
第424行: | 第363行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <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</ | + | export PATH=/usr/local/pgsql/bin:$PATH</syntaxhighlight> |
</div> | </div> | ||
第439行: | 第378行: | ||
===== psycopg2 ===== | ===== psycopg2 ===== | ||
− | + | 如上所述,安装 KyngChaos 二进制文件并修改 <code>PATH</code> 后,可以使用以下命令安装 <code>psycopg2</code>: | |
− | |||
<div class="highlight-console notranslate"> | <div class="highlight-console notranslate"> | ||
第446行: | 第384行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <syntaxhighlight lang="console">$ python -m pip install psycopg2</syntaxhighlight> |
</div> | </div> | ||
第453行: | 第391行: | ||
<div class="admonition note"> | <div class="admonition note"> | ||
− | + | 笔记 | |
− | + | 如果您没有<code>pip</code>,请按照[[../../../../../topics/install#installing-official-release|安装说明]]进行安装。 | |
第463行: | 第401行: | ||
<div id="fink" class="section"> | <div id="fink" class="section"> | ||
− | <span id=" | + | <span id="id21"></span> |
− | ===== | + | ===== 芬克 ===== |
− | [https://schwehr.blogspot.com/ Kurt Schwehr] | + | [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。 |
− | |||
− | |||
第476行: | 第412行: | ||
<div id="macports" class="section"> | <div id="macports" class="section"> | ||
− | <span id=" | + | <span id="id25"></span> |
− | ==== | + | ==== 端口 ==== |
− | [https://www.macports.org/ MacPorts] | + | [https://www.macports.org/ MacPorts] 可用于在运行 macOS 的计算机上安装 GeoDjango 先决条件。 由于 MacPorts 仍然从源代码构建软件,因此需要 [https://developer.apple.com/xcode/ Xcode]。 |
− | |||
− | [https://developer.apple.com/xcode/ Xcode] | ||
− | + | 概括: | |
<div class="highlight-console notranslate"> | <div class="highlight-console notranslate"> | ||
第489行: | 第423行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <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</ | + | $ sudo port install libgeoip</syntaxhighlight> |
</div> | </div> | ||
第501行: | 第435行: | ||
<div class="admonition note"> | <div class="admonition note"> | ||
− | + | 笔记 | |
− | + | 您还必须修改 <code>.profile</code> 中的 <code>PATH</code>,以便可以从命令行访问 MacPorts 程序: | |
− | |||
<div class="highlight-console notranslate"> | <div class="highlight-console notranslate"> | ||
第510行: | 第443行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <syntaxhighlight lang="console">export PATH=/opt/local/bin:/opt/local/lib/postgresql93/bin</syntaxhighlight> |
</div> | </div> | ||
</div> | </div> | ||
− | + | 此外,添加 <code>DYLD_FALLBACK_LIBRARY_PATH</code> 设置,以便 Python 可以找到这些库: | |
− | |||
<div class="highlight-console notranslate"> | <div class="highlight-console notranslate"> | ||
第522行: | 第454行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <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=" | + | <span id="id27"></span> |
− | === | + | === 窗户 === |
− | + | 依次执行以下部分以在 Windows 上安装 GeoDjango。 | |
− | |||
− | <div id=" | + | <div id="id28" class="section"> |
− | ==== | + | ==== 蟒蛇 ==== |
− | [[../../../../../howto/windows| | + | [[../../../../../howto/windows|安装Python]]。 |
第553行: | 第484行: | ||
==== PostgreSQL ==== | ==== PostgreSQL ==== | ||
− | + | 首先,从[https://www.enterprisedb.com EnterpriseDB]网站下载最新的[https://www.enterprisedb.com/downloads/postgres-postgresql-downloads PostgreSQL 9.x安装程序]。 下载后,运行安装程序,按照屏幕上的说明进行操作,并保留默认选项,除非您知道更改它们的后果。 | |
− | [https://www.enterprisedb.com | ||
− | |||
− | |||
<div class="admonition note"> | <div class="admonition note"> | ||
− | + | 笔记 | |
− | + | PostgreSQL 安装程序会创建一个新的 Windows 用户作为“postgres 服务帐户”和一个 <code>postgres</code> 数据库超级用户。系统将提示您为这两个帐户设置密码 - 请务必记住它! | |
− | |||
− | |||
− | |||
</div> | </div> | ||
− | + | 安装程序完成后,它会要求在退出时启动应用程序堆栈生成器 (ASB) – 保持选中状态,因为需要安装 [[#postgisasb|PostGIS]]。 | |
− | |||
− | |||
<div class="admonition note"> | <div class="admonition note"> | ||
− | + | 笔记 | |
− | + | 如果安装成功,每次系统作为 Windows 服务启动时,PostgreSQL 服务器都会在后台运行。 <span class="menuselection">PostgreSQL 9.x</span> 开始菜单组将创建并包含 ASB 和“SQL Shell”的快捷方式,它将启动 <code>psql</code> 命令窗口。 | |
− | |||
− | |||
− | |||
− | |||
第590行: | 第509行: | ||
<span id="postgisasb"></span> | <span id="postgisasb"></span> | ||
− | ==== | + | ==== 地理信息系统 ==== |
− | + | 在 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> | ||
− | <span class="menuselection">PostgreSQL Database Server 9.x on port 5432</span> | ||
− | |||
− | |||
− | + | 单击下一步后,系统将提示您选择镜像,将下载 PostGIS,并开始安装 PostGIS。 在安装过程中只选择默认选项(例如,不要取消选中创建默认 PostGIS 数据库的选项)。 | |
− | |||
− | |||
− | |||
<div class="admonition note"> | <div class="admonition note"> | ||
− | + | 笔记 | |
− | + | 系统将提示您在“数据库连接信息”对话框中输入 <code>postgres</code> 数据库超级用户密码。 | |
− | |||
第614行: | 第525行: | ||
</div> | </div> | ||
− | <div id=" | + | <div id="id31" class="section"> |
==== psycopg2 ==== | ==== psycopg2 ==== | ||
− | + | <code>psycopg2</code> Python 模块提供了 Python 和 PostgreSQL 数据库之间的接口。 下载适用于您的 Python 和 PostgreSQL 版本的最新 [http://www.stickpeople.com/projects/python/win-psycopg/ Windows 安装程序] ,并使用默认设置运行。 [[#id36|2]] | |
− | PostgreSQL | ||
− | |||
第626行: | 第535行: | ||
<div id="osgeo4w" class="section"> | <div id="osgeo4w" class="section"> | ||
− | <span id=" | + | <span id="id34"></span> |
==== OSGeo4W ==== | ==== OSGeo4W ==== | ||
− | + | [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 不需要,可以安全地取消选中。 单击下一步后,软件包将自动下载并安装,之后您可以退出安装程序。 | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
第641行: | 第544行: | ||
<div id="modify-windows-environment" class="section"> | <div id="modify-windows-environment" class="section"> | ||
− | ==== | + | ==== 修改Windows环境 ==== |
− | + | 为了使用 GeoDjango,您需要将 Python 和 OSGeo4W 目录添加到 Windows 系统 <code>Path</code>,并创建 <code>GDAL_DATA</code> 和 <code>PROJ_LIB</code> 环境变量。 下面的命令集,可以用 <code>cmd.exe</code> 执行,将设置它: | |
− | |||
− | |||
− | |||
<div class="highlight-bat notranslate"> | <div class="highlight-bat notranslate"> | ||
第652行: | 第552行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <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 | + | reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /f /d "%PATH%" |
− | reg ADD | + | reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v GDAL_DATA /t REG_EXPAND_SZ /f /d "%GDAL_DATA%" |
− | reg ADD | + | 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"> | ||
− | + | 笔记 | |
− | + | 执行这些命令需要管理员权限。 为此,请使用命令创建 <code>bat</code> 脚本,右键单击它,然后选择 <span class="menuselection"> 以管理员身份运行 </span>。 您需要注销并重新登录才能使设置生效。 | |
− | |||
− | |||
− | |||
第677行: | 第574行: | ||
<div class="admonition note"> | <div class="admonition note"> | ||
− | + | 笔记 | |
− | + | 如果您自定义了 Python 或 OSGeo4W 安装目录,则需要相应地修改 <code>OSGEO4W_ROOT</code> 和/或 <code>PYTHON_ROOT</code> 变量。 | |
− | |||
− | |||
第689行: | 第584行: | ||
<div id="install-django-and-set-up-database" class="section"> | <div id="install-django-and-set-up-database" class="section"> | ||
− | ==== | + | ==== 安装 Django 并设置数据库 ==== |
+ | |||
+ | 最后, [[../../../../../topics/install#installing-official-release|在你的系统上安装 Django]]。 | ||
− | + | 脚注 | |
− | + | ; <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] 打包和维护。 | ||
− | |||
− | |||
− | |||
− | |||
+ | </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 安装需要:
以下各节提供了每个要求和安装说明的详细信息。 此外,平台特定的说明可用于:
使用源
因为 GeoDjango 利用了最新的开源地理空间软件技术,所以需要最新版本的库。 如果二进制包不适用于您的平台,则可能需要从源代码安装。 从源代码编译库时,请严格按照说明进行操作,特别是如果您是初学者。
要求
空间数据库
目前支持的空间数据库有 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 可能的组合。
安装
地理空间图书馆
数据库安装
将 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 配置文件中放置以下内容:
设置系统库路径
在 GNU/Linux 系统上,通常在 /etc/ld.so.conf
中有一个文件,其中可能包含来自另一个目录中文件的附加路径,例如 /etc/ld.so.conf.d
。 作为 root 用户,在 ld.so.conf
的新行中添加自定义库路径(如 /usr/local/lib
)。 这是如何执行此操作的 one 示例:
对于 OpenSolaris 用户,可以使用 crle
实用程序修改系统库路径。 不带选项运行 crle
以查看当前配置并使用 crle -l
设置新的库路径。 修改系统库路径时要非常小心:
安装 binutils
GeoDjango 使用 find_library
函数(来自 ctypes.util
Python 模块)来发现库。 find_library
例程使用一个名为 objdump
(binutils
包的一部分)的程序来验证 GNU/Linux 系统上的共享库。 因此,如果 binutils
未安装在您的 Linux 系统上,那么即使您的库路径设置正确并且地理空间库已完美构建,Python 的 ctypes 也可能无法找到您的库。
可以使用以下命令在 Debian 和 Ubuntu 系统上安装 binutils
软件包:
同样,在 Red Hat 和 CentOS 系统上:
特定于平台的说明
macOS
由于适用于 macOS 的打包系统多种多样,用户有多种不同的选项来安装 GeoDjango。 这些选项是:
- Postgres.app(最简单和推荐)
- 家酿
- KyngChaos 套餐
- 芬克
- 端口
- 从源头构建
本节还包括从 Python 软件基金会提供的包中安装 Python 升级版本的说明,但这不是必需的。
蟒蛇
虽然 macOS 安装了 Python,但用户可以使用 Python Software Foundation 提供的 框架安装程序 。 使用安装程序的一个优势是 macOS 的 Python 将保持“原始”供内部操作系统使用。
笔记
您需要修改 .profile
文件中的 PATH
环境变量,以便在命令行输入 python
时使用新版本的 Python:
Postgres.app
Postgres.app 是一个独立的 PostgreSQL 服务器,包括 PostGIS 扩展。 您还需要使用 Homebrew 安装 gdal
和 libgeoip
。
安装 Postgres.app 后,将以下内容添加到 .bash_profile
中,以便您可以从命令行运行包的程序。 将 X.Y
替换为您安装的 Postgres.app 中的 PostgreSQL 版本:
您可以通过在终端提示符下键入 which psql
来检查路径是否设置正确。
家酿
Homebrew 提供了从源代码构建二进制文件和包的“方法”。 它为运行 macOS 的 Macintosh 计算机上的 GeoDjango 先决条件提供了方法。 由于 Homebrew 仍然从源代码构建软件,因此需要 Xcode。
概括:
KyngChaos 套餐
William Kyngesburye 提供了许多 地理空间库二进制包 ,它们有助于在 macOS 上安装 GeoDjango,而无需从源代码编译它们。 然而,Xcode 仍然需要编译 Python 数据库适配器 psycopg2(用于 PostGIS)。
下载框架包:
- UnixImageIO
- 项目
- 地球观测站
- SQLite3(包括 SpatiaLite 库)
- GDAL
按照上面列出的顺序安装包,因为 GDAL 和 SQLite 包需要在它们之前列出的包。
之后,您还可以为 PostgreSQL 和 PostGIS 安装 KyngChaos 二进制包。
安装二进制包后,您需要将以下内容添加到 .profile
中,以便能够从命令行运行包程序:
窗户
依次执行以下部分以在 Windows 上安装 GeoDjango。
PostgreSQL
首先,从EnterpriseDB网站下载最新的PostgreSQL 9.x安装程序。 下载后,运行安装程序,按照屏幕上的说明进行操作,并保留默认选项,除非您知道更改它们的后果。
笔记
PostgreSQL 安装程序会创建一个新的 Windows 用户作为“postgres 服务帐户”和一个 postgres
数据库超级用户。系统将提示您为这两个帐户设置密码 - 请务必记住它!
安装程序完成后,它会要求在退出时启动应用程序堆栈生成器 (ASB) – 保持选中状态,因为需要安装 PostGIS。
笔记
如果安装成功,每次系统作为 Windows 服务启动时,PostgreSQL 服务器都会在后台运行。 psql
命令窗口。
地理信息系统
在 Application Stack Builder 中(要在安装程序之外运行,
),从下拉列表中选择 菜单。 接下来,展开 菜单树并选择 。单击下一步后,系统将提示您选择镜像,将下载 PostGIS,并开始安装 PostGIS。 在安装过程中只选择默认选项(例如,不要取消选中创建默认 PostGIS 数据库的选项)。
笔记
系统将提示您在“数据库连接信息”对话框中输入 postgres
数据库超级用户密码。
psycopg2
psycopg2
Python 模块提供了 Python 和 PostgreSQL 数据库之间的接口。 下载适用于您的 Python 和 PostgreSQL 版本的最新 Windows 安装程序 ,并使用默认设置运行。 2
OSGeo4W
OSGeo4W 安装程序 有助于安装 GeoDjango 所需的 PROJ.4、GDAL 和 GEOS 库。 首先,下载 OSGeo4W 安装程序 ,并运行它。 选择 ,点击下一步。 在“选择包”列表中,确保选择了 GDAL; MapServer 和 Apache 也默认启用,但 GeoDjango 不需要,可以安全地取消选中。 单击下一步后,软件包将自动下载并安装,之后您可以退出安装程序。
修改Windows环境
为了使用 GeoDjango,您需要将 Python 和 OSGeo4W 目录添加到 Windows 系统 Path
,并创建 GDAL_DATA
和 PROJ_LIB
环境变量。 下面的命令集,可以用 cmd.exe
执行,将设置它:
笔记
执行这些命令需要管理员权限。 为此,请使用命令创建 bat
脚本,右键单击它,然后选择 。 您需要注销并重新登录才能使设置生效。
笔记
如果您自定义了 Python 或 OSGeo4W 安装目录,则需要相应地修改 OSGEO4W_ROOT
和/或 PYTHON_ROOT
变量。
安装 Django 并设置数据库
最后, 在你的系统上安装 Django。
脚注
- 1
- GeoDjango 使用
ctypes.util
中的find_library()
例程来定位共享库。 - 2
psycopg2
Windows 安装程序由 Jason Erickson 打包和维护。