【发布时间】:2020-01-09 22:42:50
【问题描述】:
我使用 boto3 从单独的 ec2 实例启动 EMR 集群,并使用如下所示的引导脚本:
#!/bin/bash
############################################################################
#For all nodes including master #########
############################################################################
wget https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh
bash Anaconda3-2019.10-Linux-x86_64.sh -b -p /mnt1/anaconda3
export PATH=/mnt1/anaconda3/bin:$PATH
echo "export PATH="/mnt1/anaconda3/bin:$PATH"" >> ~/.bash_profile
sudo sed -i -e '$a\export PYSPARK_PYTHON=/mnt1/anaconda3/bin/python' /etc/spark/conf/spark-env.sh
echo "export PYSPARK_PYTHON="/mnt1/anaconda3/bin/python3"" >> ~/.bash_profile
conda install -c conda-forge -y shap
conda install -c conda-forge -y lightgbm
conda install -c anaconda -y numpy
conda install -c anaconda -y pandas
conda install -c conda-forge -y pyarrow
conda install -c anaconda -y boto3
############################################################################
#For master #########
############################################################################
if [ `grep 'isMaster' /mnt/var/lib/info/instance.json | awk -F ':' '{print $2}' | awk -F ',' '{print $1}'` = 'true' ]; then
sudo sed -i -e '$a\export PYSPARK_PYTHON=/mnt1/anaconda3/bin/python' /etc/spark/conf/spark-env.sh
echo "export PYSPARK_PYTHON="/mnt1/anaconda3/bin/python3"" >> ~/.bash_profile
sudo yum -y install git-core
conda install -c conda-forge -y jupyterlab
conda install -y jupyter
conda install -c conda-forge -y s3fs
conda install -c conda-forge -y nodejs
pip install spark-df-profiling
jupyter labextension install jupyterlab_filetree
jupyter labextension install @jupyterlab/toc
fi
然后我使用 add_job_flow_steps 以编程方式向正在运行的集群添加一个步骤
action = conn.add_job_flow_steps(JobFlowId=curr_cluster_id, Steps=layer_function_steps)
步骤是完美形成的火花提交。
在其中一个导入的 python 文件中,我导入了 boto3。我得到的错误是
ImportError: No module named boto3
显然我正在安装这个库。如果我 SSH 进入主节点并运行
python
import boto3
它工作正常。由于我正在进行 conda 安装,使用已安装的库是否存在某种问题?
【问题讨论】:
-
您还需要在您的环境中添加
export PYSPARK_DRIVER_PYTHON="/mnt1/anaconda3/bin/python3",以告诉驱动程序使用哪个python
标签: pyspark boto3 amazon-emr spark-submit