从 python 代码为 spark 设置环境变量 [英] setting environment variables from python code for spark
本文介绍了从 python 代码为 spark 设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在 Mac os 中设置了环境变量来运行 pyspark
I have set the environment variables in Mac os to run pyspark
export SPARK_HOME=/Users/devesh/Downloads/spark-1.5.1-bin-hadoop2.6
export PYTHONPATH=$SPARK_HOME/python/:$PYTHONPATH
export PYTHONPATH=$SPARK_HOME/python/lib/py4j-0.8.2.1-src.zip:$PYTHONPATH
以上几行对我有用.
我正在尝试使用以下 python 代码行在 python 中复制上述命令
I am trying to replicate the above commands in python using the following lines of python code
os.environ['SPARK_HOME']="/Users/devesh/Downloads/spark-1.5.1-bin-hadoop2.6"
spark_home=os.environ.get('SPARK_HOME',None)
sys.path.append("/Users/devesh/Downloads/spark-1.5.1-bin-hadoop2.6/python/")
sys.path.insert(0,os.path.join(spark_home,'py4j-0.8.2.1-src.zip'))
但它不起作用.请告诉我我做错了什么?
but it is not working. Please tell me what am I doing wrong?
推荐答案
你的最后一行 python 代码:
Your last line of python code:
sys.path.insert(0,os.path.join(spark_home,'py4j-0.8.2.1-src.zip'))
与您的 shell 代码不一致.您可以将其更改为:
is inconsistent with your shell code. You may change it to:
sys.path.insert(0,os.path.join(spark_home,'python','lib','py4j-0.8.2.1-src.zip'))
这篇关于从 python 代码为 spark 设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文