python自带的shell、其性能优于ipython_python - 如何使用PySpark加载IPython Shell - 堆栈内存溢出...

本文介绍了如何配置ptpython以在CLI上获得ipython功能和vi或emacs键绑定,特别是在使用Spark时。通过修改环境变量和安装ptpython,用户可以在pyspark会话中享受更丰富的代码提示和编辑体验。此外,还提到了如何在Python脚本中设置PYSPARK_PYTHON和PYSPARK_DRIVER_PYTHON以提交Spark应用。
摘要由CSDN通过智能技术生成

我使用ptpython(1) ,它提供ipython功能以及您选择的vi(1)或emacs(1)键绑定。 它还提供了动态代码弹出/智能功能,这在CLI上进行临时SPARK工作或只是尝试学习Spark API时非常有用。

这是启用vi的 ptpython会话的样子,请注意screehshot底部的VI(INSERT)模式,以及ipython样式提示,表明已选择了这些ptpython功能(有关如何选择的更多信息)一会儿):

aHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9tRzJTSi5wbmc=

要获得所有这些,请执行以下简单步骤 :

user@linux$ pip3 install ptpython # Everything here assumes Python3

user@linux$ vi ${SPARK_HOME}/conf/spark-env.sh

# Comment-out/disable the following two lines. This is necessary because

# they take precedence over any UNIX environment settings for them:

# PYSPARK_PYTHON=/path/to/python

# PYSPARK_DRIVER_PYTHON=/path/to/python

user@linux$ vi ${HOME}/.profile # Or whatever your login RC-file is.

# Add these two lines:

export PYSPARK_PYTHON=python3 # Fully-Qualify this if necessary. (python3)

export PYSPARK_DRIVER_PYTHON=ptpython3 # Fully-Qualify this if necessary. (ptpython3)

user@linux$ . ${HOME}/.profile # Source the RC file.

user@linux$ pyspark

# You are now running pyspark(1) within ptpython; a code pop-up/interactive

# shell; with your choice of vi(1) or emacs(1) key-bindings; and

# your choice of ipython functionality or not.

要选择您的pypython偏好设置(有很多),只需在ptpython会话中按F2键,然后选择所需的任何选项即可。

结束语 :如果要提交Python Spark应用程序(与通过CLI与pyspark(1)进行交互(如上所示) 相反 ),只需在Python中以编程方式设置PYSPARK_PYTHON和PYSPARK_DRIVER_PYTHON ,如下所示:

os.environ['PYSPARK_PYTHON'] = 'python3'

os.environ['PYSPARK_DRIVER_PYTHON'] = 'python3' # Not 'ptpython3' in this case.

我希望这个答案和设置有用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值