

# 将 Python 库与 Amazon Glue 结合使用
Python 库

 您可以安装其他 Python 模块和库，以便与 Amazon Glue ETL 一起使用。对于 Amazon Glue 2.0 及更高版本，Amazon Glue 使用 Python Package Installer（pip3）安装 Amazon Glue ETL 使用的其他模块。AmazonGlue 提供了多种选项，来将其他 Python 模块引入 Amazon Glue 作业环境。您可以使用 `--additional-python-modules` 参数，通过以下方式引入新模块：使用包含捆绑 Python wheels 的 zip 文件（也称为“zip of wheels”，适用于 Amazon Glue 5.0 及更高版本）、单个 Python wheel 文件、需求文件（requirements.txt，适用于 Amazon Glue 5.0 及更高版本）或以逗号分隔的 Python 模块列表。该参数也可用于更改 Amazon Glue 环境中提供的 Python 模块的版本（更多详情请参阅 [Amazon Glue 中已提供的 Python 模块](#glue-modules-provided)）。

**Topics**
+ [

## 使用 pip 在 Amazon Glue 2.0 或更高版本中安装其他 Python 模块
](#addl-python-modules-support)
+ [

## 包含具有 PySpark 原生功能的 Python 文件
](#extra-py-files-support)
+ [

## 使用视觉对象转换的编程脚本
](#aws-glue-programming-with-cvt)
+ [

## 压缩库以用于包含
](#aws-glue-programming-python-libraries-zipping)
+ [

## 加载 Amazon Glue Studio 笔记本中的 Python 库
](#aws-glue-programming-python-libraries-notebooks)
+ [

## 通过 Amazon Glue 0.9/1.0 在开发端点中加载 Python 库
](#aws-glue-programming-python-libraries-dev-endpoint)
+ [

## 在作业或作业运行中使用 Python 库
](#aws-glue-programming-python-libraries-job)
+ [

## 主动分析 Python 依赖项
](#aws-glue-programming-analyzing-python-dependencies)
+ [

## Amazon Glue 中已提供的 Python 模块
](#glue-modules-provided)
+ [

## 附录 A：创建 Zip of Wheels 构件
](#glue-python-library-zip-of-wheels-appendix)
+ [

## 附录 B：Amazon Glue 环境详细信息
](#glue-python-libraries-environment-details)

## 使用 pip 在 Amazon Glue 2.0 或更高版本中安装其他 Python 模块


Amazon Glue 使用 Python Package Installer（pip3）安装 Amazon Glue ETL 使用的其他模块。您可以将 `--additional-python-modules` 参数与逗号分隔的 Python 模块列表结合使用，以添加新模块或更改现有模块的版本。您可以通过 zip of wheels 或独立的 wheel 构件安装构建的 wheel 构件:方法是将文件上传到 Amazon S3，然后在模块列表中包含 Amazon S3 对象的路径。有关设置作业参数的更多信息，请参阅[在 Amazon Glue 作业中使用作业参数](https://docs.amazonaws.cn/glue/latest/dg/aws-glue-programming-etl-glue-arguments.html)。

 您可以使用 `--python-modules-installer-option` 参数将其他选项传递给 pip3。例如，您可以传递 `--only-binary` 参数，强制 pip 仅安装由 `--additional-python-modules` 指定的包的预构建构件。有关更多示例，请参阅 [Building Python modules from a wheel for Spark ETL workloads using Amazon Glue 2.0](https://www.amazonaws.cn/blogs/big-data/building-python-modules-from-a-wheel-for-spark-etl-workloads-using-aws-glue-2-0/)。

### Python 依赖项管理的最佳实践


对于生产工作负载，Amazon Glue 建议将所有 Python 依赖项打包成一个 zip 构件中的 wheel 文件。此方法可提供：
+ **确定性执行**：精确控制安装哪些包版本
+ **可靠性**：作业执行期间无需依赖任何外部包存储库
+ **性能**：只需一次下载操作，无需多次网络调用
+ **离线安装**：可在无法访问互联网的私有 VPC 环境中运行

#### 重要注意事项


根据 [Amazon 责任共担模式](https://www.amazonaws.cn/compliance/shared-responsibility-model/)，您负责管理其他 Python 模块、库及其依赖项。这包括：
+ **安全更新**：定期更新包以解决安全漏洞
+ **版本兼容性**：确保包与您的 Amazon Glue 版本兼容
+ **测试**：验证打包的依赖项可在 Glue 环境中正常运行

如果依赖项较少，则可以考虑改用单独的 wheel 文件。

### （推荐）使用 Zip of Wheels 在 Amazon Glue 5.0 或更高版本中安装其他 Python 库


Amazon Glue 5.0 及更高版本支持将多个 wheel 文件打包成一个包含捆绑 Python wheels 的 zip 构件，以实现更可靠和更具确定性的依赖项管理。要使用此方法，请创建一个包含所有 wheel 依赖项及其传递依赖项的 zip 文件（采用 `.gluewheels.zip` 后缀），将其上传到 Amazon S3，然后使用 `--additional-python-modules` 参数引用该文件。确保将 `--no-index` 添加到 `--python-modules-installer-option` 作业参数。通过此配置，zip of wheels 文件本质上充当 pip 的本地索引，用于在运行时解析依赖项。这可消除在作业执行期间对 PyPI 等外部包存储库的依赖，从而为生产工作负载提供更高的稳定性和一致性。例如：

```
--additional-python-modules s3://amzn-s3-demo-bucket/path/to/zip-of-wheels-1.0.0.gluewheels.zip
--python-modules-installer-option --no-index
```

有关如何创建 zip of wheels 文件的说明，请参阅 [附录 A：创建 Zip of Wheels 构件](#glue-python-library-zip-of-wheels-appendix)。

### 使用 Wheel 安装其他 Python 库


Amazon Glue 支持使用存储在 Amazon S3 中的 wheel (.whl) 文件安装自定义 Python 包。要在 Amazon Glue 作业中包含 wheel 文件，请在 `--additional-python-modules` 作业参数中提供以逗号分隔的 wheel 文件（存储在 s3 中）列表。例如：

```
--additional-python-modules s3://amzn-s3-demo-bucket/path/to/package-1.0.0-py3-none-any.whl,s3://your-bucket/path/to/another-package-2.1.0-cp311-cp311-linux_x86_64.whl
```

当您需要使用自定义发行版，或具有针对相关操作系统预编译的原生依赖项的软件包时，也可以使用此方法。有关更多示例，请参阅 [Building Python modules from a wheel for Spark ETL workloads using Amazon Glue 2.0](https://www.amazonaws.cn/blogs/big-data/building-python-modules-from-a-wheel-for-spark-etl-workloads-using-aws-glue-2-0/)。

### 使用 requirements.txt 在 Amazon Glue 5.0 或更高版本中安装其他 Python 库


在 Amazon Glue 5.0\$1 中，您可以提供事实标准 `requirements.txt` 来管理 Python 库依赖项。为此，请提供下面的两个作业参数：
+ 键：`--python-modules-installer-option`

  值：`-r`
+ 键：`--additional-python-modules`

  值：`s3://path_to_requirements.txt`

Amazon Glue 5.0 节点最初加载 `requirements.txt` 中指定的 python 库。

下面是示例 requirements.txt：

```
awswrangler==3.9.1
elasticsearch==8.15.1
PyAthena==3.9.0
PyMySQL==1.1.1
PyYAML==6.0.2
pyodbc==5.2.0
pyorc==0.9.0
redshift-connector==2.1.3
scipy==1.14.1
scikit-learn==1.5.2
SQLAlchemy==2.0.36
```

**重要**  
请谨慎使用此选项，尤其是在生产工作负载中。在运行时从 PyPI 中拉取依赖项风险很大，因为您无法确定 pip 解析到哪个构件。使用未固定的库版本尤其危险，因为其会拉取最新版本的 Python 模块，从而引入重大更改或不兼容的 Python 模块。这可能由于 Amazon Glue 作业环境中的 Python 安装失败而导致作业失败。虽然固定库版本可以提高稳定性，但 pip 解析仍不完全确定，因此可能会引发类似的问题。作为最佳实践，Amazon Glue 建议使用冻结的构件，例如 zip of wheels 或单个 wheel 文件（更多详情请参阅[（推荐）使用 Zip of Wheels 在 Amazon Glue 5.0 或更高版本中安装其他 Python 库](#glue-python-library-installing-zip-of-wheels)）。

**重要**  
如果您没有固定传递依赖项的版本，则主依赖项可能会拉取不兼容的传递依赖项版本。作为最佳实践，应固定所有库版本以提高 Amazon Glue 作业的一致性。更好的办法是，Amazon Glue 建议将依赖项打包成 zip of wheels 文件，从而确保生产工作负载的最大一致性和可靠性。

### 安装直接配置为逗号分隔列表的其他 Python 库


Amazon Glue 允许通过传递 `--additional-python-modules` 参数，将以逗号分隔的 Python 模块列表作为值，从而更新或添加新的 Python 模块。例如，可使用以下键/值来更新/添加 scikit-learn 模块：`"--additional-python-modules", "scikit-learn==0.21.3"`。您可以通过两种方式直接配置 python 模块。
+ **固定 Python 模块**

  `"--additional-python-modules", "scikit-learn==0.21.3,ephem==4.1.6"`
+ **未固定的 Python 模块：（不建议用于生产工作负载）**

  `"--additional-python-modules", "scikit-learn>==0.20.0,ephem>=4.0.0"`

  或

  `"--additional-python-modules", "scikit-learn,ephem"`

**重要**  
请谨慎使用此选项，尤其是在生产工作负载中。在运行时从 PyPI 中拉取依赖项风险很大，因为您无法确定 pip 解析到哪个构件。使用未固定的库版本尤其危险，因为其会拉取最新版本的 Python 模块，从而引入重大更改或不兼容的 Python 模块。这可能由于 Amazon Glue 作业环境中的 Python 安装失败而导致作业失败。虽然固定库版本可以提高稳定性，但 pip 解析仍不完全确定，因此可能会引发类似的问题。作为最佳实践，Amazon Glue 建议使用冻结的构件，例如 zip of wheels 或单个 wheel 文件（更多详情请参阅[（推荐）使用 Zip of Wheels 在 Amazon Glue 5.0 或更高版本中安装其他 Python 库](#glue-python-library-installing-zip-of-wheels)）。

**重要**  
如果您没有固定传递依赖项的版本，则主依赖项可能会拉取不兼容的传递依赖项版本。作为最佳实践，应固定所有库版本以提高 Amazon Glue 作业的一致性。更好的办法是，Amazon Glue 建议将依赖项打包成 zip of wheels 文件，从而确保生产工作负载的最大一致性和可靠性。

## 包含具有 PySpark 原生功能的 Python 文件


Amazon Glue 使用 PySpark 在 Amazon Glue ETL 作业中包含 Python 文件。如果可用，您希望使用 `--additional-python-modules` 管理依赖项。您可以使用 `--extra-py-files` 作业参数以包含 Python 文件。依赖关系必须托管在 Amazon S3 中，参数值应为逗号分隔的 Amazon S3 路径列表，且不含空格。此功能的行为类似于您将在 Spark 中使用的 Python 依赖项管理。有关 Spark 中 Python 依赖项管理的更多信息，请参阅 Apache Spark 文档中的 [Using PySpark Native Features](https://spark.apache.org/docs/latest/api/python/tutorial/python_packaging.html#using-pyspark-native-features)（使用 PySpark 原生功能）页面。如果其他代码未打包，或您使用现有工具链迁移 Spark 程序以管理依赖项时，`--extra-py-files` 非常有用。为使依赖项工具可维护，您必须在提交之前捆绑依赖项。

## 使用视觉对象转换的编程脚本


 使用 Amazon Glue Studio 可视化界面创建 Amazon Glue 作业时，您可以使用托管式的数据转换节点和自定义视觉对象转换来转换数据。有关托管式数据转换节点的更多信息，请参阅 [使用 Amazon Glue 托管转换转换数据](edit-jobs-transforms.md)。有关自定义视觉对象转换的更多信息，请参阅 [使用自定义视觉转换来转换数据](custom-visual-transform.md)。只有当作业的**语言**设置为使用 Python 时，才能生成使用视觉对象转换的脚本。

 生成使用视觉对象转换的 Amazon Glue 作业时，Amazon Glue Studio 将使用作业配置中的 `--extra-py-files` 参数将这些转换包含在运行时环境中。有关任务参数的更多信息，请参阅 [在 Amazon Glue 作业中使用作业参数](aws-glue-programming-etl-glue-arguments.md)。对生成的脚本或运行时环境进行更改时，需要保留此作业配置以确保脚本的成功运行。

## 压缩库以用于包含
压缩库

除非库包含在单个 `.py` 文件中，否则它应打包到 `.zip` 存档中。包目录应该位于存档文件的根部，并且必须包含一个针对该包的 `__init__.py` 文件。然后，Python 将能够以正常方式导入包。

如果您的库仅在一个 `.py` 文件中包含单个 Python 模块，您无需将其放入 `.zip` 文件。

## 加载 Amazon Glue Studio 笔记本中的 Python 库
笔记本中的库

 要在 Amazon Glue Studio Notebook 中指定 Python 库，请参阅[安装其他 Python 模块](https://docs.amazonaws.cn/glue/latest/dg/manage-notebook-sessions.html#specify-default-modules)。

## 通过 Amazon Glue 0.9/1.0 在开发端点中加载 Python 库
开发终端节点中的库

如果对不同的 ETL 脚本使用不同的库集，则可以为每个集设置单独的开发终端节点，也可以覆盖每次您切换脚本时开发终端节点加载的库 `.zip` 文件。

在创建开发终端节点时，您可以使用控制台为其指定一个或多个库 .zip 文件。在分配名称和 IAM 角色后，请选择 **Script Libraries and job parameters (optional) (脚本库和任务参数（可选）)**，然后在 **Python library path (脚本库路径)** 框中输入库 `.zip` 文件的完整 Amazon S3 路径。例如：

```
s3://bucket/prefix/site-packages.zip
```

如果需要，您可以指定文件的多个完整路径并使用逗号分隔，但不能有空格，如下所示：

```
s3://bucket/prefix/lib_A.zip,s3://bucket_B/prefix/lib_X.zip
```

如果您更新这些 `.zip` 文件，则可以使用控制台将其重新导入到您的开发终端节点。导航到所涉开发人员终端节点，选中它旁边的框，然后从 **Action** 菜单中选择 **Update ETL libraries**。

类似地，您可以使用 Amazon Glue API 指定库文件。当您通过调用 [CreateDevEndpoint 操作（Python：create\$1dev\$1endpoint）](aws-glue-api-dev-endpoint.md#aws-glue-api-dev-endpoint-CreateDevEndpoint) 创建开发终端节点时，可以通过如下所示的调用在 `ExtraPythonLibsS3Path` 参数中指定库的一个或多个完整路径：

```
dep = glue.create_dev_endpoint(
             EndpointName="testDevEndpoint",
             RoleArn="arn:aws:iam::123456789012",
             SecurityGroupIds="sg-7f5ad1ff",
             SubnetId="subnet-c12fdba4",
             PublicKey="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCtp04H/y...",
             NumberOfNodes=3,
             ExtraPythonLibsS3Path="s3://bucket/prefix/lib_A.zip,s3://bucket_B/prefix/lib_X.zip")
```

当您更新一个开发终端节点时，还可以通过在调用 [UpdateDevEndpoint (update\$1dev\$1endpoint)](aws-glue-api-dev-endpoint.md#aws-glue-api-dev-endpoint-UpdateDevEndpoint) 时使用 [DevEndpointCustomLibraries](aws-glue-api-dev-endpoint.md#aws-glue-api-dev-endpoint-DevEndpointCustomLibraries) 对象并将 `UpdateEtlLibraries ` 参数设置为 `True` 来更新它所加载的库。

## 在作业或作业运行中使用 Python 库
作业中的库

当您在控制台上创建新任务时，可以通过选择 **Script Libraries and job parameters (optional) (脚本库和任务参数 (可选))** 并输入完整的 Amazon S3 库路径来指定一个或多个库 .zip 格式文件（方法与创建开发终端节点时相同）：

```
s3://bucket/prefix/lib_A.zip,s3://bucket_B/prefix/lib_X.zip
```

如果您正在调用 [CreateJob (create\$1job)](aws-glue-api-jobs-job.md#aws-glue-api-jobs-job-CreateJob)，则可以使用 `--extra-py-files` 默认参数指定默认库的一个或多个完整路径，如下所示：

```
job = glue.create_job(Name='sampleJob',
                      Role='Glue_DefaultRole',
                      Command={'Name': 'glueetl',
                               'ScriptLocation': 's3://my_script_bucket/scripts/my_etl_script.py'},
                      DefaultArguments={'--extra-py-files': 's3://bucket/prefix/lib_A.zip,s3://bucket_B/prefix/lib_X.zip'})
```

然后，当您启动作业运行时，可以使用其他设置覆盖默认库设置：

```
runId = glue.start_job_run(JobName='sampleJob',
                           Arguments={'--extra-py-files': 's3://bucket/prefix/lib_B.zip'})
```

## 主动分析 Python 依赖项
分析 Python 依赖项

 要在部署到 Amazon Glue 之前主动识别潜在的依赖项问题，您可以使用依赖项分析工具，根据目标 Amazon Glue 环境验证您的 Python 包。

 Amazon 提供了专为 Amazon Glue 环境设计的开源 Python 依赖项分析器工具。该工具可从 Amazon Glue 示例存储库中获取并在本地使用，从而在部署之前验证依赖项。

 此分析有助于确保依赖项遵循推荐的做法，即固定所有库版本以确保生产部署的一致性。有关更多详细信息，请参阅该工具的 [README](https://github.com/aws-samples/aws-glue-samples/tree/master/utilities/glue_python_dependency_analyzer) 文件。

### 使用 Amazon Glue 依赖项分析器


 Amazon Glue Python 依赖项分析器通过使用与目标 Amazon Glue 环境匹配的特定平台约束来模拟 pip 安装，从而帮助识别未固定的依赖项和版本冲突。

```
# Analyze a single Glue job
python glue_dependency_analyzer.py -j my-glue-job

# Analyze multiple jobs with specific AWS configuration
python glue_dependency_analyzer.py -j job1 -j job2 --aws-profile production --aws-region us-west-2
```

 该工具将标记以下问题：
+  未固定的依赖项，这可能会导致在作业运行中安装不同的版本 
+  软件包之间的版本冲突 
+  不支持目标 Amazon Glue 环境的依赖项 

## 使用 Amazon Q 开发者版分析和修复因 Python 依赖项导致的作业失败问题


 Amazon Q 开发者版是一款由生成式人工智能（AI）提供支持的对话式助手，可为您理解、构建、扩展和操作 Amazon 应用程序提供帮助。您可以按照 Amazon Q 入门指南中的说明进行下载该工具。

 Amazon Q 开发者版可用于分析和修复因 Python 依赖项导致的作业失败问题。我们建议使用以下提示，并将作业的 <Job-Name> 占位符替换为 Glue 作业的名称。

```
I have an AWS Glue job named <Job-Name> that has failed due to Python module installation conflicts. Please assist in diagnosing and resolving this issue using the following systematic approach. Proceed once sufficient information is available.

Objective: Implement a fix that addresses the root cause module while minimizing disruption to the existing working environment.

Step 1: Root Cause Analysis
• Retrieve the most recent failed job run ID for the specified Glue job
• Extract error logs from CloudWatch Logs using the job run ID as a log stream prefix
• Analyze the logs to identify:
  • The recently added or modified Python module that triggered the dependency conflict
  • The specific dependency chain causing the installation failure
  • Version compatibility conflicts between required and existing modules

Step 2: Baseline Configuration Identification
• Locate the last successful job run ID prior to the dependency failure
• Document the Python module versions that were functioning correctly in that baseline run
• Establish the compatible version constraints for conflicting dependencies

Step 3: Targeted Resolution Implementation
• Apply pinning by updating the job's additional_python_modules parameter
• Pin only the root cause module and its directly conflicting dependencies to compatible versions, and do not remove python modules unless necessary
• Preserve flexibility for non-conflicting modules by avoiding unnecessary version constraints
• Deploy the configuration changes with minimal changes to the existing configuration and execute a validation test run. Do not change the Glue versions.

Implementation Example:
Scenario: Recently added pandas==2.0.0 to additional_python_modules
Error: numpy version conflict (pandas 2.0.0 requires numpy>=1.21, but existing job code requires numpy<1.20)
Resolution: Update additional_python_modules to "pandas==1.5.3,numpy==1.19.5"
Rationale: Use pandas 1.5.3 (compatible with numpy 1.19.5) and pin numpy to last known working version

Expected Outcome: Restore job functionality with minimal configuration changes while maintaining system stability.
```

 该提示符将指示 Q 执行以下操作：

1. 获取最新的失败作业运行 ID

1. 查找关联的日志和详细信息

1. 查找成功的作业运行以检测任何发生更改的 Python 软件包

1. 执行配置修复并启动新的测试运行

## Amazon Glue 中已提供的 Python 模块


要更改这些已提供模块的版本，请使用 `--additional-python-modules` 作业参数提供新版本。

------
#### [ Amazon Glue version 5.1 ]

Amazon Glue 5.1 版包括以下开箱即用的 Python 模块：
+ aiobotocore==2.25.1
+ aiohappyeyeballs==2.6.1
+ aiohttp==3.13.2
+ aioitertools==0.12.0
+ aiosignal==1.4.0
+ appdirs==1.4.4
+ attrs==25.4.0
+ boto3==1.40.61
+ botocore==1.40.61
+ certifi==2025.10.5
+ charset-normalizer==3.4.4
+ choreographer==1.2.0
+ contourpy==1.3.3
+ cycler==0.12.1
+ distlib==0.4.0
+ filelock==3.20.0
+ fonttools==4.60.1
+ frozenlist==1.8.0
+ fsspec==2025.10.0
+ idna==3.11
+ iniconfig==2.3.0
+ jmespath==1.0.1
+ kaleido==1.2.0
+ kiwisolver==1.4.9
+ logistro==2.0.1
+ matplotlib==3.10.7
+ multidict==6.7.0
+ narwhals==2.10.2
+ numpy==2.3.4
+ orjson==3.11.4
+ packaging==25.0
+ pandas==2.3.3
+ pillow==12.0.0
+ pip==24.0
+ platformdirs==4.5.0
+ plotly==6.4.0
+ pluggy==1.6.0
+ propcache==0.4.1
+ pyarrow==22.0.0
+ Pygments==2.19.2
+ pyparsing==3.2.5
+ pytest-timeout==2.4.0
+ pytest==8.4.2
+ python-dateutil==2.9.0.post0
+ pytz==2025.2
+ requests==2.32.5
+ s3fs==2025.10.0
+ s3transfer==0.14.0
+ seaborn==0.13.2
+ setuptools==79.0.1
+ simplejson==3.20.2
+ six==1.17.0
+ tenacity==9.1.2
+ typing\$1extensions==4.15.0
+ tzdata==2025.2
+ urllib3==2.5.0
+ uv==0.9.7
+ virtualenv==20.35.4
+ wrapt==1.17.3
+ yarl==1.22.0

------
#### [ Amazon Glue version 5.0 ]

Amazon Glue 5.0 版包括以下开箱即用的 Python 模块：
+ aiobotocore==2.13.1
+ aiohappyeyeballs==2.3.5
+ aiohttp==3.10.1
+ aioitertools==0.11.0
+ aiosignal==1.3.1
+ appdirs==1.4.4
+ attrs==24.2.0
+ boto3==1.34.131
+ botocore==1.34.131
+ certifi==2024.7.4
+ charset-normalizer==3.3.2
+ contourpy==1.2.1
+ cycler==0.12.1
+ fonttools==4.53.1
+ frozenlist==1.4.1
+ fsspec==2024.6.1
+ idna==2.10
+ jmespath==0.10.0
+ kaleido==0.2.1
+ kiwisolver==1.4.5
+ matplotlib==3.9.0
+ multidict==6.0.5
+ numpy==1.26.4
+ packaging==24.1
+ pandas==2.2.2
+ pillow==10.4.0
+ pip==23.0.1
+ plotly==5.23.0
+ pyarrow==17.0.0
+ pyparsing==3.1.2
+ python-dateutil==2.9.0.post0
+ pytz==2024.1
+ requests==2.32.2
+ s3fs==2024.6.1
+ s3transfer==0.10.2
+ seaborn==0.13.2
+ setuptools==59.6.0
+ six==1.16.0
+ tenacity==9.0.0
+ tzdata==2024.1
+ urllib3==1.25.10
+ virtualenv==20.4.0
+ wrapt==1.16.0
+ yarl==1.9.4

------
#### [ Amazon Glue version 4.0 ]

Amazon Glue 4.0 版包括以下开箱即用的 Python 模块：
+ aiobotocore==2.4.1
+ aiohttp==3.8.3
+ aioitertools==0.11.0
+ aiosignal==1.3.1
+ async-timeout==4.0.2
+ asynctest==0.13.0
+ attrs==22.2.0
+ avro-python3==1.10.2
+ boto3==1.24.70
+ botocore==1.27.59
+ certifi==2021.5.30
+ chardet==3.0.4
+ charset-normalizer==2.1.1
+ click==8.1.3
+ cycler==0.10.0
+ Cython==0.29.32
+ fsspec==2021.8.1
+ idna==2.10
+ importlib-metadata==5.0.0
+ jmespath==0.10.0
+ joblib==1.0.1
+ kaleido==0.2.1
+ kiwisolver==1.4.4
+ matplotlib==3.4.3
+ mpmath==1.2.1
+ multidict==6.0.4
+ nltk==3.7
+ numpy==1.23.5
+ packaging==23.0
+ pandas==1.5.1
+ patsy==0.5.1
+ pillow==9.4.0
+ pip==23.0.1
+ plotly==5.16.0
+ pmdarima==2.0.1
+ ptvsd==4.3.2
+ pyarrow==10.0.0
+ pydevd==2.5.0
+ pyhocon==0.3.58
+ pymysql==1.0.2
+ pyparsing==2.4.7
+ python-dateutil==2.8.2
+ pytz==2021.1
+ PyYAML==6.0.1
+ regex==2022.10.31
+ requests==2.23.0
+ s3fs==2022.11.0
+ s3transfer==0.6.0
+ scikit-learn==1.1.3
+ scipy==1.9.3
+ setuptools==49.1.3
+ six==1.16.0
+ statsmodels==0.13.5
+ subprocess32==3.5.4
+ sympy==1.8
+ tbats==1.1.0
+ threadpoolctl==3.1.0
+ tqdm==4.64.1
+ typing\$1extensions==4.4.0
+ urllib3==1.25.11
+ wheel==0.37.0
+ wrapt==1.14.1
+ yarl==1.8.2
+ zipp==3.10.0

------
#### [ Amazon Glue version 3.0 ]

Amazon Glue 3.0 版包括以下开箱即用的 Python 模块：
+ aiobotocore==1.4.2
+ aiohttp==3.8.3
+ aioitertools==0.11.0
+ aiosignal==1.3.1
+ async-timeout==4.0.2
+ asynctest==0.13.0
+ attrs==22.2.0
+ avro-python3==1.10.2
+ boto3==1.18.50
+ botocore==1.21.50
+ certifi==2021.5.30
+ chardet==3.0.4
+ charset-normalizer==2.1.1
+ click==8.1.3
+ cycler==0.10.0
+ Cython==0.29.4
+ docutils==0.17.1
+ enum34==1.1.10
+ frozenlist==1.3.3
+ fsspec==2021.8.1
+ idna==2.10
+ importlib-metadata==6.0.0
+ jmespath==0.10.0
+ joblib==1.0.1
+ kiwisolver==1.3.2
+ matplotlib==3.4.3
+ mpmath==1.2.1
+ multidict==6.0.4
+ nltk==3.6.3
+ numpy==1.19.5
+ packaging==23.0
+ pandas==1.3.2
+ patsy==0.5.1
+ pillow==9.4.0
+ pip==23.0
+ pmdarima==1.8.2
+ ptvsd==4.3.2
+ pyarrow==5.0.0
+ pydevd==2.5.0
+ pyhocon==0.3.58
+ pymysql==1.0.2
+ pyparsing==2.4.7
+ python-dateutil==2.8.2
+ pytz==2021.1
+ PyYAML==5.4.1
+ regex==2022.10.31
+ requests==2.23.0
+ s3fs==2021.8.1
+ s3transfer==0.5.0
+ scikit-learn==0.24.2
+ scipy==1.7.1
+ six==1.16.0
+ spark==1.0
+ statsmodels==0.12.2
+ subprocess32==3.5.4
+ sympy==1.8
+ tbats==1.1.0
+ threadpoolctl==3.1.0
+ tqdm==4.64.1
+ typing\$1extensions==4.4.0
+ urllib3==1.25.11
+ wheel==0.37.0
+ wrapt==1.14.1
+ yarl==1.8.2
+ zipp==3.12.0

------
#### [ Amazon Glue version 2.0 ]

Amazon Glue 2.0 版包括以下开箱即用的 Python 模块：
+ avro-python3==1.10.0
+ awscli==1.27.60
+ boto3==1.12.4
+ botocore==1.15.4
+ certifi==2019.11.28
+ chardet==3.0.4
+ click==8.1.3
+ colorama==0.4.4
+ cycler==0.10.0
+ Cython==0.29.15
+ docutils==0.15.2
+ enum34==1.1.9
+ fsspec==0.6.2
+ idna==2.9
+ importlib-metadata==6.0.0
+ jmespath==0.9.4
+ joblib==0.14.1
+ kiwisolver==1.1.0
+ matplotlib==3.1.3
+ mpmath==1.1.0
+ nltk==3.5
+ numpy==1.18.1
+ pandas==1.0.1
+ patsy==0.5.1
+ pmdarima==1.5.3
+ ptvsd==4.3.2
+ pyarrow==0.16.0
+ pyasn1==0.4.8
+ pydevd==1.9.0
+ pyhocon==0.3.54
+ PyMySQL==0.9.3
+ pyparsing==2.4.6
+ python-dateutil==2.8.1
+ pytz==2019.3
+ PyYAML==5.3.1
+ regex==2022.10.31
+ requests==2.23.0
+ rsa==4.7.2
+ s3fs==0.4.0
+ s3transfer==0.3.3
+ scikit-learn==0.22.1
+ scipy==1.4.1
+ setuptools==45.2.0
+ six==1.14.0
+ spark==1.0
+ statsmodels==0.11.1
+ subprocess32==3.5.4
+ sympy==1.5.1
+ tbats==1.0.9
+ tqdm==4.64.1
+ typing-extensions==4.4.0
+ urllib3==1.25.8
+ wheel==0.35.1
+ zipp==3.12.0

------

## 附录 A：创建 Zip of Wheels 构件


我们通过示例演示如何创建 zip of wheels 构件。所示的示例将 `cryptography` 和 `scipy` 包下载到 zip of wheels 构件中，然后将 zip of wheels 复制到 Amazon S3 位置。

1. 您必须在与 Glue 环境类似的 Amazon Linux 环境中运行命令才能创建 zip of wheels。请参阅[附录 B：Amazon Glue 环境详细信息](#glue-python-libraries-environment-details)。Glue 5.1 使用 AL2023 及 Python 版本 3.11。创建将构建此环境的 Dockerfile：

   ```
   FROM --platform=linux/amd64 public.ecr.aws/amazonlinux/amazonlinux:2023-minimal
   
   # Install Python 3.11, pip, and zip utility
   RUN dnf install -y python3.11 pip zip && \
       dnf clean all
   
   WORKDIR /build
   ```

1. 创建 requirements.txt 文件

   ```
   cryptography
   scipy
   ```

1. 构建并启动 Docker 容器

   ```
   # Build docker image
   docker build --platform linux/amd64 -t glue-wheel-builder .
   
   # Spin up container
   docker run --platform linux/amd64 -v $(pwd)/requirements.txt:/input/requirements.txt:ro -v $(pwd):/output -it glue-wheel-builder bash
   ```

1. 在 Docker 映像中运行以下命令

   ```
   # Create a directory for the wheels
   mkdir wheels
   
   # Copy requirements.txt into wheels directory
   cp /input/requirements.txt wheels/
   
   # Download the wheels with the correct platform and Python version
   pip3 download \
       -r wheels/requirements.txt \
       --dest wheels/ \
       --platform manylinux2014_x86_64 \
       --python-version 311 \
       --only-binary=:all:
   
   # Package the wheels into a zip archive with the .gluewheels.zip suffix
   zip -r mylibraries-1.0.0.gluewheels.zip wheels/
   
   # Copy zip to output
   cp mylibraries-1.0.0.gluewheels.zip /output/
   
   # Exit the container
   exit
   ```

1. 将 zip of wheels 上传到 Amazon S3 位置

   ```
   aws s3 cp mylibraries-1.0.0.gluewheels.zip s3://amzn-s3-demo-bucket/example-prefix/
   ```

1. 可选的清理

   ```
   rm mylibraries-1.0.0.gluewheels.zip
   rm Dockerfile
   rm requirements.txt
   ```

1. 使用以下作业参数运行 Glue 作业：

   ```
   --additional-python-modules s3://amzn-s3-demo-bucket/example-prefix/mylibraries-1.0.0.gluewheels.zip
   --python-modules-installer-option --no-index
   ```

## 附录 B：Amazon Glue 环境详细信息



**Glue 版本兼容性和安装方法**  

| Amazon Glue 版本 | Python 版本 | 基础 映像 | glibc 版本 | 兼容的平台标签 | 
| --- | --- | --- | --- | --- | 
| 5.1 | 3.11 | [Amazon Linux 2023 (AL2023)](https://www.amazonaws.cn/linux/amazon-linux-2023/) | 2.34 |  manylinux\$12\$134\$1x86\$164 manylinux\$12\$128\$1x86\$164 manylinux2014\$1x86\$164  | 
| 5.0 | 3.11 | [Amazon Linux 2023 (AL2023)](https://www.amazonaws.cn/linux/amazon-linux-2023/) | 2.34 |  manylinux\$12\$134\$1x86\$164 manylinux\$12\$128\$1x86\$164 manylinux2014\$1x86\$164  | 
| 4.0 | 3.10 | [Amazon Linux 2 (AL2)](https://www.amazonaws.cn/amazon-linux-2/) | 2.26 | manylinux2014\$1x86\$164 | 
| 3.0 | 3.7 | [Amazon Linux 2 (AL2)](https://www.amazonaws.cn/amazon-linux-2/) | 2.26 | manylinux2014\$1x86\$164 | 
| 2.0 | 3.7 | [Amazon Linux AMI (AL1)](https://www.amazonaws.cn/amazon-linux-ami/) | 2.17 | manylinux2014\$1x86\$164 | 

 根据 [Amazon 责任共担模式](https://www.amazonaws.cn/compliance/shared-responsibility-model/)，您负责管理您在 Amazon Glue ETL 作业中使用的其他 Python 模块、库及其依赖项。这包括应用更新和安全补丁。

 Amazon Glue 不支持在作业环境中编译原生代码。但是，Amazon Glue 作业会在 Amazon 托管的 Linux 环境中运行。您可通过 Python wheel 文件，以编译后的形式提供原生依赖项。有关 Amazon Glue 版本兼容性的详细信息，请参阅上表。

**重要**  
 使用不兼容的依赖项可能会导致运行时问题，尤其是对于具有原生扩展的库，因为这些库必须与目标环境的架构和系统库相匹配。每个 Amazon Glue 版本都在特定的 Python 版本上运行，其中包含预装的库和系统配置。