Skip To Content

扩展 notebook 运行时

ArcGIS Notebook Server 包含两个 notebook 运行时(Python 模块的集合)。 这些运行时会通过容器映像提供给 notebook 用户,容器映像应用于您服务器站点中运行的每个容器。

标准和高级 notebook 运行时都包括 ArcGIS API for Python 和多种 Python 模块,可用于数据科学、空间分析和内容管理。 高级运行时还包括 ArcPy。

请参阅可用 Python 库的列表

在某些情况下,您的 notebook 创作者可能需要这两个运行时中未包含的模块或特定版本的模块。 您可以通过以下方法在 ArcGIS Notebook Server 中访问附加 Python 模块:

  • 在 notebook 会话期间安装一个 Python 模块。 该模块即可用于该 notebook。
  • 扩展 Esri 容器映像以在自定义运行时中包含其他 Python 库。 您创建的容器映像将使您站点中的所有 notebook 创作者都可使用扩展的运行时。

在会话期间安装模块

Notebook 创作者可以在 notebook 会话期间通过使用 condapip 包管理程序系统安装两个运行时中未包含的 Python 模块或版本模块以供使用。 建议您使用 conda,因为 ArcGIS Notebook Server 将使用其来管理模块;但是,一些 Python 模块仅在 pip 中可用。

该方法将在 notebook 会话期间安装所需模块。 关闭 notebook 或终止属于用户的容器后,该模块将不再可用。 要使用此方法安装模块,用户必须经 Internet 连接到 condapip 信道。

注:

condapip 都包含于两个 notebook 运行时中。 无需进行安装。

例如,要在会话期间安装 scrapy 包,请使用以下其中一个命令运行 notebook 单元格,具体取决于您所使用的包管理系统:

使用 conda 包管理系统

!conda install --yes scrapy

使用 pip 包管理系统

!pip install scrapy

要在使用中的 notebook 运行时中使用不同版本的 Python 模块,请在命令中指定版本号。

运行 condapip 命令之后必须重新启动内核以使新包可用。

例如,某个软件包在 1.5 版本的两个 notebook 运行时都可用,但您想使用 1.6 版本中引入的工具。 要在 notebook 会话期间使用 1.6 版本的包,请使用以下其中一个命令运行 notebook 单元格,具体取决于您所使用的包管理系统:

使用 conda 包管理系统

!conda install --yes <package name>==1.6

使用 pip 包管理系统

!pip install <package name>==1.6

构建自定义容器映像

要对 notebook 运行时进行持久更改,则可以在站点中构建自定义容器映像。 以下工作流需要管理权限,可创建自定义映像并为其使用配置 ArcGIS Notebook Server

可以使用两个 notebook 运行时之一(标准或高级)作为起点。 构建自定义运行时之后,可以将其注册为站点中的新运行时。

  1. 安装并配置 ArcGIS Notebook Server
  2. 以管理员身份登录到 ArcGIS Notebook Server Administrator Directory。

    URL 地址格式为 https://notebookserver.domain.com:11443/arcgis/admin/

  3. 单击 notebook > 运行时,然后选择要为自定义映像扩展的 notebook 运行时。

    在运行时的资源页面上,记录该运行时的 imageId 值。 在下一步骤中将使用该值。

  4. 创建一个 Dockerfile,将所需 Python 模块添加到自定义映像。

    Dockerfile 是一个简单的指令文本文件,可用于构建 Docker 容器映像。 请参阅 Dockerfile 文档了解其详细信息及最佳实践。

    在此示例中,需要向高级 notebook 运行时添加数据可视化 Pythongraphviz。 Dockerfile 中的以下代码块将控制 Docker 使用 imageId 值访问高级运行时,然后在运行时中安装 graphviz。 该 conda clean 命令是减少文件大小的最佳做法。

    # Specify the existing notebook runtime imageId as FROM
    FROM aa7a1a346e5b
    
    # Use RUN to issue a command to install, then clean
    RUN conda install graphviz \
      && conda clean -y -a

    在此示例中,您将创建一个包含 Oracle 客户端库的自定义运行时。

    ## Using a Dockerfile to build a custom notebook runtime that includes Oracle client
    FROM <replace with imageId of standard or advanced container image>
    
    ## Switch to root user for installing OS level packages. 
    USER root
    
    ## Combine OS level statements for Docker image efficiency
    RUN apt-get update && \
            apt-get install -y alien
    ## Update the url below to the desired version of Oracle client.
    RUN wget https://yum.oracle.com/repo/OracleLinux/OL8/oracle/instantclient/x86_64/getPackage/oracle-instantclient19.10-basic-19.10.0.0.0-1.x86_64.rpm
    RUN alien -i oracle-instantclient19.10-basic-19.10.0.0.0-1.x86_64.rpm
    
    ## Installing libaio1 is required only for Notebook runtimes version 5 (10.9) or earlier.  
    RUN apt-get install -y libaio1
    
    ## Switch back to arcgis user at end of the Dockerfile
    USER arcgis
  5. 将 Dockerfile 保存于计算机。
  6. 使用 Docker 命令构建新自定义容器映像。

    该映像将包含 Dockerfile 中指定的新运行时。 打开命令提示符窗口并使用以下语法运行命令:

    docker build -t <name of my new runtime>:v1.0 -f <path to my Dockerfile> .
    注:

    请确保命令以句点结尾。

    执行命令后,Docker 将构建新的容器映像。 命令输出中的最后一行为 Successfully built <imageId>,其中包含新映像的简化 ID 值。 您必须为 ArcGIS Notebook Server 站点提供其完整 imageId 值。

  7. 在命令提示符窗口中运行以下命令以获取映像 ID 值:

    docker inspect <imageId>

    自定义映像已构建完毕,且已获取其完整 imageId 值,请返回至 ArcGIS Notebook Server Administrator Directory 以注册新映像。

  8. 在 Administrator Directory 中,浏览到 notebooks > 运行时。 单击注册运行时
  9. 指定适当的值以完成注册。

    注册运行时参考主题提供了针对这些参数的指南。 准备好后,在站点上注册运行时。

  10. 打开新的 notebook 以测试此更新。 确认您添加到自定义映像的模块或模块版本在 notebook 中可用。

要将 ArcGIS Notebook Server 站点中的运行时恢复为原始设置,请使用 Administrator Directory 中的恢复出厂运行时操作。 该操作在 https://notebookserver.domain.com:11443/arcgis/admin/notebooks/runtimes/restore 中提供,并且只会恢复当前站点版本的工厂运行时。