

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 搭配 Glue 使用 Python AWS 程式庫
<a name="aws-glue-programming-python-libraries"></a>

 您可以安裝其他 Python 模組和程式庫，以與 Glue ETL AWS 搭配使用。對於 AWS Glue 2.0 及更高版本， AWS Glue 使用 Python 套件安裝程式 (pip3) 來安裝 AWS Glue ETL 使用的其他模組。 AWS Glue 提供多種選項，可將其他 Python 模組帶入您的 AWS Glue 任務環境。您可以使用 `--additional-python-modules` 參數，使用包含綁定 Python wheel 的 zip 檔案 （也稱為 "zip of wheel"，適用於 AWS Glue 5.0 及更高版本）、個別 Python wheel 檔案、需求檔案 (requirements.txt，適用於 AWS Glue 5.0 及更高版本） 或逗號分隔 Python 模組清單來引入新模組。它也可以用來變更 Glue 環境中提供的 Python AWS 模組版本 （如需詳細資訊[Python 模組已在 Glue AWS 中提供](#glue-modules-provided)，請參閱 )。

**Topics**
+ [在 AWS Glue 2.0 或更新版本中使用 pip 安裝其他 Python 模組](#addl-python-modules-support)
+ [包括 Python 檔案與 PySpark 原生功能](#extra-py-files-support)
+ [使用視覺化轉換的程式設計指令碼](#aws-glue-programming-with-cvt)
+ [壓縮程式庫以加入](#aws-glue-programming-python-libraries-zipping)
+ [在 Glue Studio AWS 筆記本中載入 Python 程式庫](#aws-glue-programming-python-libraries-notebooks)
+ [在 Glue 0.9/1.0 的開發端點中載入 Python AWS 程式庫](#aws-glue-programming-python-libraries-dev-endpoint)
+ [在任務或 JobRun 使用 Python 程式庫](#aws-glue-programming-python-libraries-job)
+ [主動分析 Python 相依項](#aws-glue-programming-analyzing-python-dependencies)
+ [Python 模組已在 Glue AWS 中提供](#glue-modules-provided)
+ [附錄 A：建立輪子壓縮成品](#glue-python-library-zip-of-wheels-appendix)
+ [附錄 B： AWS Glue 環境詳細資訊](#glue-python-libraries-environment-details)

## 在 AWS Glue 2.0 或更新版本中使用 pip 安裝其他 Python 模組
<a name="addl-python-modules-support"></a>

AWS Glue 使用 Python 套件安裝程式 (pip3) 來安裝 AWS Glue ETL 要使用的其他模組。您可以使用 `--additional-python-modules` 參數與逗號分隔的 Python 模組清單來新增新模組或變更現有模組的版本。您可以將檔案上傳到 Amazon S3，然後在模組清單中包含 Amazon S3 物件的路徑，透過轉輪壓縮或獨立轉輪成品來安裝建置的車輪成品。如需設定任務參數的詳細資訊，請參閱[在 Glue AWS 任務中使用任務參數](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-etl-glue-arguments.html)。

 您可以使用 `--python-modules-installer-option` 參數將其他選項傳遞給 pip3。例如，您可以傳遞 `--only-binary` ，強制 pip 僅為 指定的套件安裝預先建置的成品`--additional-python-modules`。如需更多範例，請參閱[使用 Glue 2.0 從 Spark ETL AWS 工作負載的 wheel 建置 Python 模組。 ](https://aws.amazon.com/blogs/big-data/building-python-modules-from-a-wheel-for-spark-etl-workloads-using-aws-glue-2-0/)

### Python 相依性管理的最佳實務
<a name="glue-python-library-best-practices"></a>

對於生產工作負載， AWS Glue 建議將所有 Python 相依性封裝為單一 zip 成品中的 wheel 檔案。此方法提供：
+ **確定性執行**：精確控制已安裝的套件版本
+ **可靠性**：任務執行期間不依賴外部套件儲存庫
+ **效能**：單一下載操作而非多個網路呼叫
+ **離線安裝**：可在沒有網際網路存取的私有 VPC 環境中運作

#### 重要考量
<a name="glue-python-library-important-considerations"></a>

在[AWS 共同責任模型](https://aws.amazon.com/compliance/shared-responsibility-model/)下，您負責管理其他 Python 模組、程式庫及其相依性。其中包含：
+ **安全性更新**：定期更新套件以解決安全性漏洞
+ **版本相容性**：確保套件與您的 Glue AWS 版本相容
+ **測試**：驗證您的封裝相依性在 Glue 環境中是否正常運作

如果您有最少的相依性，您可以考慮改用個別的 wheel 檔案。

### （建議） 使用 Zip of Wheels AWS 在 Glue 5.0 或更高版本中安裝其他 Python 程式庫
<a name="glue-python-library-installing-zip-of-wheels"></a>

AWS Glue 5.0 及更高版本支援將多個車輪檔案封裝到包含綁定 Python 車輪的單一 zip 成品中，以實現更可靠和決定性的相依性管理。若要使用此方法，請使用`.gluewheels.zip`尾碼建立包含所有車輪相依性及其傳輸相依性的 zip 檔案，將其上傳至 Amazon S3，然後使用 `--additional-python-modules` 參數加以參考。請務必將 `--no-index` 新增至`--python-modules-installer-option`任務參數。透過此組態，輪子檔案的壓縮基本上可做為 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
```

如需如何建立 wheel 檔案 zip 的說明，請參閱 [附錄 A：建立輪子壓縮成品](#glue-python-library-zip-of-wheels-appendix)。

### 使用 Wheel 安裝其他 Python 程式庫
<a name="glue-python-library-installing-wheel"></a>

AWS Glue 支援使用存放在 Amazon S3 中的 wheel (.whl) 檔案安裝自訂 Python 套件。若要在 Glue AWS 任務中包含輪子檔案，請將儲存在 s3 中的輪子檔案逗號分隔清單提供給`--additional-python-modules`任務參數。例如：

```
--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
```

當您需要自訂發行版本，或具有原生相依項的套件已針對正確的作業系統預先編譯時，此方法也支援。如需更多範例，請參閱[使用 Glue 2.0 從 Spark ETL 工作負載的 wheel AWS 建置 Python 模組。](https://aws.amazon.com/blogs/big-data/building-python-modules-from-a-wheel-for-spark-etl-workloads-using-aws-glue-2-0/)

### 使用 requirements.txt AWS 在 Glue 5.0 或更高版本中安裝其他 Python 程式庫
<a name="addl-python-modules-requirements-txt"></a>

在 AWS Glue 5.0\$1 中，您可以提供 defacto 標準`requirements.txt`來管理 Python 程式庫相依性。若要這樣做，請提供下列兩個任務參數：
+ 索引鍵：`--python-modules-installer-option`

  值：`-r`
+ 索引鍵：`--additional-python-modules`

  值：`s3://path_to_requirements.txt`

AWS Glue 5.0 節點一開始會載入 中指定的 Python 程式庫`requirements.txt`。

以下是範例 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 模組。這可能會導致任務失敗，因為 AWS Glue 任務環境中的 Python 安裝失敗。雖然鎖定程式庫版本可提高穩定性，但 pip 解析度仍未完全確定，因此可能會出現類似的問題。最佳實務是， AWS Glue 建議使用凍結的成品，例如輪子的壓縮或個別的輪子檔案 （如需詳細資訊[（建議） 使用 Zip of Wheels AWS 在 Glue 5.0 或更高版本中安裝其他 Python 程式庫](#glue-python-library-installing-zip-of-wheels)，請參閱 )。

**重要**  
如果您未鎖定傳輸相依性的版本，則主要相依性可能會提取不相容的傳輸相依性版本。最佳實務是，所有程式庫版本都應固定，以提高 Glue AWS 任務的一致性。更好的是， AWS Glue 建議將您的相依性封裝到 wheel 壓縮檔中，以確保生產工作負載的最大一致性和可靠性。

### 直接將其他 Python 程式庫設定為逗號分隔清單
<a name="glue-python-library-installing-comma-separated-list"></a>

若要更新 或 新增 Python 模組 AWS Glue，允許使用逗號分隔 Python 模組的清單做為值傳遞`--additional-python-modules`參數。例如，若要更新或新增 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 模組。這可能會導致任務失敗，因為 AWS Glue 任務環境中的 Python 安裝失敗。雖然鎖定程式庫版本可提高穩定性，但 pip 解析度仍未完全確定，因此可能會出現類似的問題。最佳實務是， AWS Glue 建議使用凍結的成品，例如輪子的壓縮或個別的輪子檔案 （如需詳細資訊[（建議） 使用 Zip of Wheels AWS 在 Glue 5.0 或更高版本中安裝其他 Python 程式庫](#glue-python-library-installing-zip-of-wheels)，請參閱 )。

**重要**  
如果您未鎖定傳輸相依性的版本，則主要相依性可能會提取不相容的傳輸相依性版本。最佳實務是，所有程式庫版本都應固定，以提高 Glue AWS 任務的一致性。更好的是， AWS Glue 建議將您的相依性封裝到 wheel 壓縮檔中，以確保生產工作負載的最大一致性和可靠性。

## 包括 Python 檔案與 PySpark 原生功能
<a name="extra-py-files-support"></a>

AWS Glue 使用 PySpark 在 Glue ETL AWS 任務中包含 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` 非常有用。為了使您的相依性工具可維護，您必須在提交之前綁定相依性。

## 使用視覺化轉換的程式設計指令碼
<a name="aws-glue-programming-with-cvt"></a>

 當您使用 AWS Glue Studio 視覺化界面建立 Glue AWS 任務時，您可以使用受管資料轉換節點和自訂視覺化轉換來轉換資料。如需有關受管資料轉換節點的詳細資訊，請參閱[使用 AWS Glue 受管轉換來轉換資料](edit-jobs-transforms.md)。如需有關自訂視覺化轉換的詳細資訊，請參閱[使用自訂視覺化轉換來轉換資料](custom-visual-transform.md)。只有在任務**語言**設定為使用 Python 時，才能使用視覺化轉換產生指令碼。

 使用視覺化轉換產生 AWS Glue 任務時， AWS Glue Studio 會使用任務組態中的 `--extra-py-files` 參數，將這些轉換包含在執行時間環境中。如需有關任務參數的詳細資訊，請參閱 [在 Glue AWS 任務中使用任務參數](aws-glue-programming-etl-glue-arguments.md)。對產生的指令碼或執行時期環境進行變更時，您需要保留此任務組態，指令碼才能成功執行。

## 壓縮程式庫以加入
<a name="aws-glue-programming-python-libraries-zipping"></a>

除非程式庫包含在單一的 `.py` 檔案裡，否則應封裝於 `.zip` 封存中。套件目錄應位於封存的根目錄，且套件必須包含一個 `__init__.py` 檔案。接著 Python 就可以正常匯入套件。

如果程式庫僅由一個 `.py` 檔案裡的單一 Python 模組組成，則不必將其置於 `.zip` 檔案。

## 在 Glue Studio AWS 筆記本中載入 Python 程式庫
<a name="aws-glue-programming-python-libraries-notebooks"></a>

 若要在 Glue Studio AWS 筆記本中指定 Python 程式庫，請參閱[安裝其他 Python 模組。 ](https://docs.aws.amazon.com/glue/latest/dg/manage-notebook-sessions.html#specify-default-modules)

## 在 Glue 0.9/1.0 的開發端點中載入 Python AWS 程式庫
<a name="aws-glue-programming-python-libraries-dev-endpoint"></a>

若要將不同的程式庫集用於不同的 ETL 指令碼，您可以為各程式庫集設定個別的開發端點，或是覆寫每次切換指令碼時開發端點載入的程式庫 `.zip` 檔案。

在建立開發端點時，您可以使用主控台為其指定一或多個程式庫 .zip 檔案。指派名稱和 IAM 角色後，請選擇 **Script Libraries and job parameters (optional)** [指令碼程式庫與任務參數 (選用)]，並在 `.zip`Python library path** (Python 程式庫路徑) 方塊中輸入程式庫 ** 檔案的完整 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** (更新 ETL 程式庫)。

以類似的方式，您可以使用 Glue APIs AWS 指定程式庫檔案。呼叫 [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")
```

更新開發端點時，您也可以更新其載入的程式庫，方式是使用 [DevEndpointCustomLibraries](aws-glue-api-dev-endpoint.md#aws-glue-api-dev-endpoint-DevEndpointCustomLibraries) 物件，並在呼叫 [UpdateDevEndpoint (update\$1dev\$1endpoint)](aws-glue-api-dev-endpoint.md#aws-glue-api-dev-endpoint-UpdateDevEndpoint) 時將 `UpdateEtlLibraries ` 參數設定為 `True`。

## 在任務或 JobRun 使用 Python 程式庫
<a name="aws-glue-programming-python-libraries-job"></a>

在主控台建立新任務時，您可以指定一個或多個程式庫 .zip 檔案，方式是選擇 **Script Libraries and job parameters (optional) (指令碼程式庫與任務參數 (選用))**，並以與建立開發端點相同的方式輸入完整 Amazon S3 路徑：

```
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'})
```

接著，啟動 JobRun 時，您可以用不同的內容覆寫預設程式庫設定：

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

## 主動分析 Python 相依項
<a name="aws-glue-programming-analyzing-python-dependencies"></a>

 若要在部署至 Glue AWS 之前主動識別潛在的相依性問題，您可以使用相依性分析工具，針對目標 Glue 環境驗證 Python AWS 套件。

 AWS 提供專為 Glue 環境設計的開放原始碼 Python AWS 相依性分析器工具。此工具可在 AWS Glue 範例儲存庫中使用，並可在本機用來在部署之前驗證您的相依性。

 此分析有助於確保您的相依項遵循固定所有程式庫版本以實現一致生產部署的建議實務。如需詳細資訊，請參閱工具的 [README](https://github.com/aws-samples/aws-glue-samples/tree/master/utilities/glue_python_dependency_analyzer)。

### 使用 AWS Glue 相依性分析器
<a name="w2aac67c11c14c18c37c11b1"></a>

 AWS Glue Python 相依性分析器透過使用符合您目標 Glue AWS 環境的平台特定限制來模擬 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
```

 工具會標記：
+  可跨任務執行安裝不同版本的未固定相依項 
+  套件之間的版本衝突 
+  您的目標 Glue AWS 環境無法使用相依性 

## 使用 Amazon Q Developer 分析和修正因 Python 相依項造成的任務失敗
<a name="aws-glue-programming-analyze-job-failures-with-amazon-q"></a>

 Amazon Q Developer 是生成式人工智慧 (AI) 支援的對話式助理，可協助您了解、建置、擴展和操作 AWS 應用程式。您可以遵循 Amazon Q 入門指南中的指示進行下載。

 Amazon Q Developer 可用於分析和修正因 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. 進行任何組態修正並觸發另一個測試執行

## Python 模組已在 Glue AWS 中提供
<a name="glue-modules-provided"></a>

若要變更這些已提供模組的版本，請提供帶有 `--additional-python-modules` 任務參數的新版本。

------
#### [ AWS Glue version 5.1 ]

AWS 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
+ 編排人員==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
+ blocked=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
+ 請求==2.32.5
+ s3fs==2025.10.0
+ s3transfer==0.14.0
+ seaborn==0.13.2
+ setuptools==79.0.1
+ simplejson==3.20.2
+ 六==1.17.0
+ 韌性==9.1.2
+ type\$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

------
#### [ AWS Glue version 5.0 ]

AWS 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
+ blocked==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

------
#### [ AWS Glue version 4.0 ]

AWS 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

------
#### [ AWS Glue version 3.0 ]

AWS 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

------
#### [ AWS Glue version 2.0 ]

AWS 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：建立輪子壓縮成品
<a name="glue-python-library-zip-of-wheels-appendix"></a>

我們示範如何建立輪子成品的壓縮。顯示的範例會將套件 `cryptography`和 下載`scipy`到輪子成品的壓縮中，並將輪子的壓縮複製到 Amazon S3 位置。

1. 您必須執行命令，以在類似 Glue 環境的 Amazon Linux 環境中建立輪子的壓縮。請參閱 [附錄 B： AWS 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. 將輪子的壓縮上傳到 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： AWS Glue 環境詳細資訊
<a name="glue-python-libraries-environment-details"></a>


**Glue 版本相容性和安裝方法**  

| AWS Glue 版本 | Python 版本 | 基礎映像 | glibc 版本 | 相容平台標籤 | 
| --- | --- | --- | --- | --- | 
| 5.1 | 3.11 | [Amazon Linux 2023 (AL2023)](https://aws.amazon.com/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://aws.amazon.com/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://aws.amazon.com/amazon-linux-2/) | 2.26 | manylinux2014\$1x86\$164 | 
| 3.0 | 3.7 | [Amazon Linux 2 (AL2)](https://aws.amazon.com/amazon-linux-2/) | 2.26 | manylinux2014\$1x86\$164 | 
| 2.0 | 3.7 | [Amazon Linux AMI (AL1)](https://aws.amazon.com/amazon-linux-ami/) | 2.17 | manylinux2014\$1x86\$164 | 

 在[AWS 共同責任模型](https://aws.amazon.com/compliance/shared-responsibility-model/)下，您負責管理與 Glue ETL 任務搭配使用的其他 Python AWS 模組、程式庫及其相依性。這包括套用更新和安全性修補程式。

 AWS Glue 不支援在任務環境中編譯原生程式碼。不過， AWS Glue 任務會在 Amazon 受管 Linux 環境中執行。透過 Python wheel 檔案，您也許能夠以編譯形式提供原生相依項。如需 Glue AWS 版本相容性詳細資訊，請參閱上表。

**重要**  
 使用不相容的相依項可能會導致執行時期問題，尤其是對於必須與目標環境的架構和系統庫相符的原生延伸模組的程式庫。每個 AWS Glue 版本都會在具有預先安裝程式庫和系統組態的特定 Python 版本上執行。