![](/img/trans.png)
[英]Where does the output message go when submitting a Python file to Spark using spark-submit
[英]Where is executed python script when use spark-submit?
Python : 3.7.3
OS: CentOS 7
Spark: 2.2.0
In Cloudera
YARN : 2.6.0-cdh5.10.2
嗨,我嘗試使用python腳本和pyspark執行Apache Spark ,但我不明白它是如何工作的工作流程。 我嘗試在執行spark-submit
時使用--archives
參數在客戶端模式下使用紗線發送整個conda 環境。 但問題是,主要的 python 腳本在哪里運行,因為我需要指定我的共享 conda 環境的位置以在沒有錯誤的情況下執行,因為在我嘗試執行spark-submit
的主機中我沒有安裝依賴項,並且我不想安裝它。
I use this feature to pack the enviroment https://conda.github.io/conda-pack/spark.html , and I need to import the dependencies outside of a map (because inside a map, the yarn shipped the dependencies and the執行器很好地導入了這個依賴項)。
有沒有一種方法可以在不打開並在主機上使用的情況下使用附帶的環境執行主要的 python 腳本?
我的環境是:
PYSPARK_DRIVER_PYTHON=./enviroment/bin/python
PYSPARK_PYTHON=./enviroment/bin/python
其中 environment 是 yarn 附帶的依賴項的符號鏈接
--archives ~/dependencies.tar.gz#enviroment
並配置執行者
--conf spark.yarn.appMasterEnv.PYSPARK_DRIVER_PYTHON=./environment/bin/python
所以最后的命令是
PYSPARK_DRIVER_PYTHON=./enviroment/bin/python \
PYSPARK_PYTHON=./environment/bin/python \
spark-submit \
--conf spark.yarn.appMasterEnv.PYSPARK_PYTHON=./environment/bin/python \
--master yarn --deploy-mode client \
--archives enviroment/dependencies.tar.gz#enviroment \
cluster-import-check.py
我的代碼是
# coding=utf8
from pyspark import SparkConf
from pyspark import SparkContext
import sys
import numpy
def check_import(version, info=None):
print("=====VERSION : ", version)
if info and type(info) == list and len(info) != 0:
for i in info:
print("=====INFO EXTRA : ", i)
def python_import(x):
import sys
print("\n===PYTHON")
check_import(sys.version, [sys.executable])
def numpy_import(x):
import numpy
print("\n===NUMPY")
check_import(numpy.__version__, [numpy.__file__])
def printInfo(object):
print("=====NAME : ", object.__name__)
if object.__name__ == 'sys':
print("=====VERSION", object.version)
print("=====LOCATED IN", object.executable)
else:
print("=====VERSION : ", object.__version__)
print("=====LOCATED IN : ", object.__file__)
if object.__name__ == 'elasticsearch':
es = elasticsearch.Elasticsearch(['172.22.248.206:9201'])
print("=====MORE INFO : ", es.info())
def init_spark():
conf = SparkConf()
conf.setAppName("imports-checking")
sc = SparkContext(conf=conf).getOrCreate()
return conf, sc
def main():
conf, sc = init_spark()
print(sc.getConf().getAll())
print(sc.parallelize([0]).map(lambda x: python_import(x)).collect())
sc.stop()
if __name__ == '__main__':
printInfo(sys)
printInfo(numpy)
main()
一個錯誤是no module named numpy
或位於的python是其他的,因為集群中有另一個版本的python,但我想在集群上使用yarn自帶的整個環境。
我最近了解了 PysPark 與 Yarn 的工作流程,答案是如果你想在客戶端模式下運行你需要安裝(在你執行 spark-submit 的主機上)在 function 映射之外導入的所有庫。 另一方面,如果你想在集群模式下運行,你只需要在 spark-submit 命令中使用 --archives 選項來發送庫。
當它被執行時,它必須在本地完成,必須在 spark-submit 的執行中配置 PYSPARK_DRIVER_PYTHON
PYSPARK_DRIVER_PYTHON=./dependencies/bin/python spark-submit --master local --py-files cognition.zip MainScript.py
執行在執行 spark-submit 命令的主機上進行。 必須添加環境變量
PYSPARK_DRIVER_PYTHON=./dependencies/bin/python spark-submit --conf spark.yarn.appMasterEnv.PYSPARK_PYTHON=./dependencies/bin/python --master yarn --deploy-mode client --archives dependencies.tar.gz#dependencies MainScript.py
執行在它創建的 yarn 容器內部進行,在集群的任意節點執行
spark-submit --conf spark.yarn.appMasterEnv.PYSPARK_PYTHON=./dependencies/bin/python --master yarn --deploy-mode cluster --archives dependencies.tar.gz#dependencies MainScript.py
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.