操作方法

操作方法:设置一个用于安装 ArcGIS Python API 的本地 Conda 通道

Last Published: September 1, 2021

摘要

ArcGIS Python API 通过 Conda(一种面向 Python 开发人员的常用包和环境管理系统)分发。 ArcGIS Python API Guide 中概述了安装此 API 的推荐方法。 对于想要在非联网计算机或位于隔离网络中的工作站上安装 API 的客户,相关安装说明可以在指南的离线安装部分中找到。

对于想要在断开连接的环境下从 Miniconda(即从受 Miniconda 支持的 ArcGIS Pro Python 命令提示符)使用 API 的高级用户,建议在本地创建一个本地 Conda 通道,然后从该通道安装 API。 本地通道将包含 API 所需的依赖项的有限集。 用户可以选择在该通道中下载和托管任意数量的其他 Python 包。

此文章描述了为 ArcGIS Python API 创建离线 Conda 通道的步骤。 请注意,必须有 一台联网且安装了 Anaconda的计算机,且安装了带有 requests 包的 Python 3.5 shell。

过程

此知识库文章随附有两个文件 arcgis_v1_dependencies(列出 ArcGIS Python API 依赖项的文本文件)以及 download_dependencies(用于从 anaconda 通道下载依赖项的 Python 脚本)。 在开始下列步骤之前,请先下载这些支持文件

  • arcgis_v1_dependencies.txt
  • download_dependencies.py

设置一个环境来运行下载 Python 脚本

安装 Anaconda。 在根环境的终端中运行以下命令,以安装所需的 conda-buildrequests 包:

$ conda install conda-build $ conda install requests

新环境现已激活并准备就绪。

下载依赖项

将随附的 Python 脚本和文本文件下载到同一位置。 然后,运行附带的 download_dependencies.py 脚本,如下所示:

$ python download_dependencies.py

脚本从 anaconda.org 在线通道下载了所有依赖项并保存到本地。 运行脚本会创建类似以下输出:

Using environment list file: .\ arcgis_v1_dependencies.txt Getting _nb_ext_conf-0.3.0-py35_0.tar.bz2 Downloaded win-64\_nb_ext_conf-0.3.0-py35_0.tar.bz2 Downloaded win-32\_nb_ext_conf-0.3.0-py35_0.tar.bz2 Downloaded linux-64\_nb_ext_conf-0.3.0-py35_0.tar.bz2 Downloaded linux-32\_nb_ext_conf-0.3.0-py35_0.tar.bz2 Error with download: osx-32 : Downloaded osx-64\_nb_ext_conf-0.3.0-py35_0.tar.bz2 Getting anaconda-client-1.5.5-py35_0.tar.bz2 Downloaded win-64\anaconda-client-1.5.5-py35_0.tar.bz2 Downloaded win-32\anaconda-client-1.5.5-py35_0.tar.bz2 Downloaded linux-64\anaconda-client-1.5.5-py35_0.tar.bz2 Downloaded linux-32\anaconda-client-1.5.5-py35_0.tar.bz2 Error with download: osx-32 : Downloaded osx-64\anaconda-client-1.5.5-py35_0.tar.bz2 ....

当它下载时,会创建具有以下结构的文件夹:

\\channel_root\ \linux-64 \linux-32 \osx-64 \osx-32 \win-64 \win-32 \noarch


为本地 Conda 通道建立索引

一旦脚本完成,Conda 即必须对此位置进行索引。 Conda 会在每个概述所存在包的文件夹中创建一个清单文件 repodata.json。 这有助于用户计算机上的 Conda 将此位置视为本地通道,并从此位置而非互联网搜索并安装包。

然后使用以下命令建立索引:

$ conda index \\path\to\channel\win-64 $ conda index \\path\to\channel\win-32 $ conda index \\path\to\channel\linux-64 $ conda index \\path\to\channel\linux-32 $ conda index \\path\to\channel\osx-64 $ conda index \\path\to\channel\osx-32 $ conda index \\path\to\channel\noarch

运行命令会报告类似以下输出:

$ conda index \\path\to\channel\win-64 updating index in: \\path\to\channel\win-64 updating: pywin32-220-py35_1.tar.bz2 updating: nb_conda_kernels-2.0.0-py35_0.tar.bz2 updating: requests-2.12.1-py35_0.tar.bz2 updating: pyzmq-16.0.2-py35_0.tar.bz2 updating: _nb_ext_conf-0.3.0-py35_0.tar.bz2 updating: ipywidgets-5.2.2-py35_0.tar.bz2 updating: decorator-4.0.10-py35_0.tar.bz2 ....

完成此步骤后,将根文件夹传输到一个联网位置或 web 服务器,或者在本地将其用作本地 Conda 通道。

从本地 Conda 通道安装

在非联网计算机上安装 Anaconda 或 Miniconda。 然后,在本地通道上搜索包以确保通道可运行:

$ conda search --channel file://path/to/channel --override-channels

例如,在 Windows 计算机上,它将如下所示:

$ conda search --channel D:/code/arcgis_offline_downloads/channel --override-channels

命令将返回一个类似于以下内容的结果:

$ conda search --channel file://offline/arcgis_channel/channel --override-channels Fetching package metadata ..... _nb_ext_conf 0.3.0 py35_0 file://offline/arcgis_channel/channel anaconda-client 1.5.5 py35_0 file://offline/arcgis_channel/channel arcgis 0.9 py35_1 file://offline/arcgis_channel/channel clyent 1.2.2 py35_0 file://offline/arcgis_channel/channel colorama 0.3.7 py35_0 file://offline/arcgis_channel/channel decorator 4.0.10 py35_0 file://offline/arcgis_channel/channel ...

由于 ArcGIS 及其所有依赖项现在可搜索,因此现在可以进行安装了。 创建一个新的 Conda 环境,或在根环境下安装 arcgis 包:

conda create --name awesome_arcgis python [this step is optional]

现在从 Conda 通道安装 ArcGIS:

activate awesome_arcgis conda install --channel //offline/arcgis_channel/channel arcgis --offline --override-channels

这将打印以下内容,并在得到用户确认后继续安装:

$ conda install -c //offline/arcgis_channel/channel arcgis --offline --override-channels Fetching package metadata ..... Solving package specifications: .......... Package plan for installation in environment C:\Anaconda3\envs\awesome_arcgis: The following packages will be downloaded: package | build ---------------------------|----------------- colorama-0.3.7 | py35_0 19 KB file://offline/arcgis_channel/channel decorator-4.0.10 | py35_0 12 KB file://offline/arcgis_channel/channel .... Proceed ([y]/n)? y .... Enabling notebook extension arcgis/mapview... - Validating: ok

通过运行 Conda 列表确保安装 ArcGIS:

$ conda list # packages in environment at C:\Anaconda3\envs\awesome_arcgis: # arcgis 0.9 py35_1 file://offline/arcgis_channel/channel colorama 0.3.7 py35_0 file://offline/arcgis_channel/channel decorator 4.0.10 py35_0 file://offline/arcgis_channel/channel ...

测试离线安装

如果 ArcGIS 包已在一个新环境中安装,请激活它。 然后,从您的终端运行以下命令:

jupyter notebook

这将在浏览器中启用一个新的 notebook 环境。 启用一个新的 notebook 并键入下列内容:

from arcgis.gis import GIS() gis = GIS("portal url", "username", "password") #connect to the ArcGIS Enterprise in your local network gis.map()

这将会打开地图微件并加载默认底图。

提示和技巧

操作系统差异

  • 根据运行此脚本的操作系统,可能需要使用正斜杠替换反斜杠(在基于 Unix 的操作系统上,如 Mac、Linux 等)。
  • Python 脚本会下载适用于所有操作系统架构的包。 因此,即使目标计算机具有不同的操作系统,也无需重新运行下载和索引构建步骤。 使通道的目标计算机上的 web 服务器或 web 驱动器上可用,或通过物理方法复制到这些机器上,然后从该位置进行安装。

建立存档

如果要存档通道以便日后使用或存储,可以通过将根级别的通道文件夹及其所有子文件夹绑定到 tar 文件来完成。 使用以下命令来执行此操作。 如果是 Windows 系统,请使用 PowerShell 作为运行这些命令的终端:

$ tar -zcvf arcgis_v1_offline_channel.tar.gz path/to/channel/

运行此命令会打印类似如下所示的输出:

a channel a channel/.DS_Store a channel/linux-32 a channel/linux-64 a channel/osx-32 a channel/osx-64 a channel/win-32 a channel/win-64 a channel/win-64/.index.json a channel/win-64/_nb_ext_conf-0.3.0-py35_0.tar.bz2 a channel/win-64/anaconda-client-1.5.5-py35_0.tar.bz2 a channel/win-64/arcgis-1.0-py35_1.tar.bz2 a channel/win-64/clyent-1.2.2-py35_0.tar.bz2 ....

要解压此存档以供日后使用,请运行以下命令:

$ tar -zxcf arcgis_v1_offline_channel.tar.gz -C ./arcgis_channel

文章 ID:000014951

从 ArcGIS 专家处获得帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项

相关信息

发现关于本主题的更多内容