New user sign up using AWS Builder ID
New user sign up using AWS Builder ID is currently unavailable on re:Post. To sign up, please use the AWS Management Console instead.
如何在 Amazon EMR 上升級我的 Python 版本,並將 PySpark 工作設定為使用升級的 Python 版本?
我想在 Amazon EMR 上升級我的 Python 版本,並將 PySpark 工作設定為使用升級的 Python 版本。
簡短說明
叢集執行個體和系統應用程式會根據下列 Amazon EMR 發行版而使用不同的 Python 版本:
- Amazon EMR 發行版 4.6.0 至 5.19.0: Python 3.4 安裝在叢集執行個體上。Python 2.7 是系統預設版本。
- Amazon EMR 發行版 5.20.0 及更高版本: Python 3.6 安裝在叢集執行個體上。對於 Amazon EMR 版本 5.20.0 至 5.29.0,Python 2.7 是系統預設版本。對於 5.30.0 及更高版本,Python 3 是系統預設版本。
- Amazon EMR 發行版 6.0.0 及更高版本: Python 3.7 安裝在叢集執行個體上。Python 3 是系統預設版本。
- Amazon EMR 發行版 7.0.0 及更高版本: Python 3.9 安裝在叢集執行個體上。Python 3 是系統預設版本。
解決方法
注意: 如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤,則請參閱對 AWS CLI 進行錯誤疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本。
若要升級 Python 版本,請將用於 spark-env 分類的 PYSPARK_PYTHON 環境變數指向安裝新版 Python 的目錄:
which example-python-version
注意: 用新的 Python 版本取代 example-python-version。
為執行於 Amazon EC2 上的 Amazon EMR 升級 Python 版本
注意: 在 Amazon EMR 叢集執行個體上安裝新的 Python 和 OpenSSL 版本之前,請務必先行測試下列指令碼。
若要為執行於 Amazon Elastic Compute Cloud (Amazon EC2) 的 Amazon EMR 6.15 版升級至 Python 3.9,請使用下列指令碼。您也可以使用指令碼,在 Amazon EMR 7.0 版上升級至 Python 3.10 或更高版本:
sudo yum -y install openssl-devel bzip2-devel libffi-devel xz-devel gcc sqlite-devel wget https://www.python.org/ftp/python/3.x.x/example-python3-version.tgz tar xvf example-python3-version.tgz cd example-python3-version/ ./configure --enable-optimizations sudo make altinstall
注意: 用您的 Python 3 版本取代 example-python3-version。
您需要 OpenSSL 才能在 Amazon EMR 6.15 或更早版本上升級至 Python 3.10 或更高版本。請使用下列指令碼:
sudo yum -y install openssl-devel bzip2-devel libffi-devel xz-devel gcc sqlite-devel cd /home/hadoop/ wget https://github.com/openssl/openssl/archive/refs/tags/example-openssl11-version.tar.gz tar -xzf example-openssl11-version.tar.gz cd example-openssl11-version/ ./config --prefix=/usr --openssldir=/etc/ssl --libdir=lib no-shared zlib-dynamic make sudo make install cd /home/hadoop/ wget https://www.python.org/ftp/python/3.x.x/example-python3-version.tgz tar xvf example-python3-version.tgz cd example-python3-version/ ./configure --enable-optimizations --with-openssl=/usr sudo make altinstall
注意: 用 Python 3 版本取代 example-python3-version,並用 OpenSSL 11 版本取代 example-openssl11-version。如需詳細資訊,請參閱 GitHub 網站上的 openssl。
若要使用升級的版本作為預設 Python 3 安裝,請使用 /usr/local/bin/python3.x 作為新的 Python 位置。先前的 Python 指令碼安裝在 /usr/local/bin/python3.x 中,預設的 Python 安裝為 /usr/bin/python3。
於正在執行的叢集上升級 Python 版本
注意: 對於 Amazon EMR 版本 5.36.0 及更早版本,您可以將 Python 版本升級至 3.8 版。
** Amazon EMR 版本 5.21.0 或更早版本**
請使用與下列項目相似的組態物件提交重新設定請求:
[ { "Classification": "spark-env", "Configurations": [ { "Classification": "export", "Properties": { "PYSPARK_PYTHON": "/usr/bin/python3" } } ] } ]
Amazon EMR 版本 4.6.0 至 5.20.x
請完成下列步驟:
- 使用 SSH 以連線至主節點。
- 若要變更預設的 Python 環境,請執行下列命令:
若要確認 PySpark 是否使用正確的 Python 版本,請執行下列命令:sudo sed -i -e '$a\export PYSPARK_PYTHON=/usr/bin/python3' /etc/spark/conf/spark-env.sh
注意: 用您的 IP 位址取代 example-ip-address。[hadoop@example-ip-address conf]$ pyspark
範例輸出結果:Python 3.4.8 (default, Apr 25 2018, 23:50:36) Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /__ / .__/\_,_/_/ /_/\_\ version 2.3.1 /_/ Using Python version 3.4.8 (default, Apr 25 2018 23:50:36) SparkSession available as 'spark'.
注意: 新的組態會在下一個 PySpark 工作上生效。
在新叢集上升級 Python 版本
若要在 Amazon EMR 上啟動叢集時升級 Python 版本,請將動程序動作新增至您使用的指令碼。
若要為執行於 Amazon EC2 的 Amazon EMR 6.15 版升級至 Python 3.9,請使用下列指令碼。您也可以使用指令碼,在 Amazon EMR 7.0 版上升級至 Python 3.10 或更高版本:
sudo yum -y install openssl-devel bzip2-devel libffi-devel xz-devel gcc sqlite-devel wget https://www.python.org/ftp/python/3.x.x/example-python3-version.tgz tar xvf example-python3-version.tgz cd example-python3-version/ ./configure --enable-optimizations sudo make altinstall
注意: 用您的 Python 3 版本取代 example-python3-version。
您需要 OpenSSL 才能在 Amazon EMR 6.15 和更早版本上升級至 Python 3.10 或更高版本。請使用下列指令碼:
sudo yum -y install openssl-devel bzip2-devel libffi-devel xz-devel gcc sqlite-devel cd /home/hadoop/ wget https://github.com/openssl/openssl/archive/refs/tags/example-openssl11-version.tar.gz tar -xzf example-openssl11-version.tar.gz cd example-openssl11-version/ ./config —prefix=/usr --openssldir=/etc/ssl --libdir=lib no-shared zlib-dynamic make sudo make install cd /home/hadoop/ wget https://www.python.org/ftp/python/3.x.x/example-python3-version.tgz tar xvf example-python3-version.tgz cd example-python3-version/ ./configure --enable-optimizations --with-openssl=/usr sudo make altinstall
注意: 用 Python 3 版本取代 example-python3-version,並用 OpenSSL 11 版本取代 example-openssl11-version。如需詳細資訊,請參閱 GitHub 網站上的 openssl。
然後,新增類似於下列項目的組態物件:
[ { "Classification": "spark-env", "Configurations": [ { "Classification": "export", "Properties": { "PYSPARK_PYTHON": "<example-python-version-path>" } } ] } ]
在 Amazon EKS 上的 Amazon EMR 升級 Python 版本
注意: Amazon Linux 2023 型映像會在名稱中包含 al2023。此外,Amazon EMR 6.13.0 及更高版本預設會在以 Amazon Linux 2023 為基礎的映像中使用 Python 3.9.16。對於以 Amazon Linux 2 為基礎的映像,預設版本為 Python 3.7。
若要為 Amazon Elastic Kubernetes Service (Amazon EKS) 上的 Amazon EMR 升級 Python 版本,您會需要一個 Docker 映像檔。請選取適用於您的 AWS 區域的基礎 URI:
FROM example-base-URI-account-id.dkr.ecr.example-region.amazonaws.com/spark/emr-6.15.0 USER root RUN yum install -y gcc openssl-devel bzip2-devel libffi-devel tar gzip wget make RUN wget https://www.python.org/ftp/python/3.x.x/example-python3-version.tgz && \ tar xzf example-python3-version.tgz && cd example-python3-version && \ ./configure --enable-optimizations && \ make altinstall USER hadoop:hadoop
注意: 使用適用於 Apache Spark 映像的基本帳戶 ID 取代 example-base-URI-account-id、使用您的區域取代 example-region,並使用 Python 版本取代 example-python3-version。
若要在提交 Spark 工作負載時傳遞映像,請使用應用程式組態覆寫 Spark 驅動程式和主要 Pod 映像:
{ "classification": "spark-defaults", "properties": { "spark.kubernetes.container.image": "example-account-id.dkr.ecr.example-region.amazonaws.com/example-repository" } }
注意: 使用儲存所建立映像的帳戶 ID 取代 example-account-id、使用儲存自訂映像的儲存庫名稱取代 example-repository,並使用您的區域取代 example-region。
在 Amazon EMR Serverless 上升級 Python 版本
若要在 Amazon EMR Serverless 應用程式上升級 Python 版本,請使用 Docker 映像檔來安裝新的 Python 版本:
FROM public.ecr.aws/emr-serverless/spark/emr-6.9.0:latest USER root # install python 3 RUN yum install -y gcc openssl-devel bzip2-devel libffi-devel tar gzip wget make RUN wget https://www.python.org/ftp/python/3.x.x/example-python3-version.tgz && \ tar xzf example-python3-version.tgz && cd example-python3-version && \ ./configure --enable-optimizations && \ make altinstall # EMRS will run the image as hadoop USER hadoop:hadoop
注意: 用 Python 3 版本取代 example-python-version。
將 Spark 工作提交至 Amazon EMR Serverless 應用程式時,請傳遞下列路徑以便使用新的 Python 版本:
--conf spark.emr-serverless.driverEnv.PYSPARK_DRIVER_PYTHON=/usr/local/bin/python3.9 --conf spark.emr-serverless.driverEnv.PYSPARK_PYTHON=/usr/local/bin/python3.9 --conf spark.executorEnv.PYSPARK_PYTHON=/usr/local/bin/python3.9
相關資訊

相關內容
- 已提問 2 年前lg...
- 已提問 4 個月前lg...
- 已提問 2 年前lg...
- AWS 官方已更新 2 年前
- AWS 官方已更新 2 年前
- AWS 官方已更新 3 年前