根据用于编译 Python 脚本的操作系统 (Operating System, OS),在将相关的 ZIP 存档导入到 Automation Orchestrator Client 后,工作流或操作可能会失败。

Automation Orchestrator 中用于 Python 的运行时容器的操作系统基于 Photon 3.0。为其他操作系统(例如 Linux)编译的 Python 脚本包与运行时容器不兼容。当您尝试在 Automation Orchestrator 工作流或操作中使用 Python 脚本时,此问题可能会导致 Python 脚本运行失败。在此类场景中,您将在日志中收到以下错误消息:

-04:00errorCannot find module action

要解决此问题,必须将所需的 Python 软件包安装到 Photon OS 容器文件夹中。

前提条件

安装 Docker。请参见获取 Docker

过程

  1. 导航到 Python 脚本的父文件夹。
  2. 通过将容器文件夹挂载到父文件夹,创建含有基础 Photon 映像的容器。
    注: 以下脚本是一个单独的 Docker 命令,您必须完整运行该命令,才能创建适当的容器。
    docker run -ti -v 
    $(pwd)/<name_of_folder_that_containes_your_python_script>/:/<name_of_folder_that_containes_your_python_script> 
    photon:3.0
  3. 在容器中安装 Python。
    tdnf install -y python3-3.7.5-5.ph3 python3-pip-3.7.5-5.ph3
  4. 导航到包含您的 Python 脚本的容器文件夹。
  5. 添加您的 Python 脚本和软件包。
    注: 将 Python 脚本所需的软件包安装到 lib 文件夹中。
     pip3 install <package_name> -t lib/ 
    
  6. 退出容器,然后导航到已挂载到容器的本地文件夹。
  7. 将所有相关文件和文件夹压缩为一个 ZIP 存档。
  8. 将该 ZIP 存档导入到 Automation Orchestrator Client,并通过在操作中运行该脚本来对其进行验证。