centos7下python远程调用spark资源

原文连接:https://blog.csdn.net/qq_16734411/article/details/83345744
原文连接:http://dblab.xmu.edu.cn/blog/1692-2/
原文连接:http://dblab.xmu.edu.cn/blog/1689-2/
centos:7.6
python:3.6.8
spark:2.4.3

先查询环境变量中知否有添加PYTHONPATH与PYSPARK_PYTHON
cd ~
vi .bash_profile # 或vi .bashrc

export PYTHONPATH=$SPARK_HOME/python:$SPARK_HOME/python/lib/py4j-0.10.7-src.zip:$PYTHONPATH
export PYSPARK_PYTHON=python3
PYTHONPATH环境变量主要是为了在Python3中引入pyspark库,PYSPARK_PYTHON变量主要是设置pyspark运行的python版本。由于我之前是将pyhton的指向直接指到python3上了,所以就没有添加PYSPARK_PYTHON这条参数

在这里插入图片描述
cd /usr/local/spark/spark-2.4.3-bin-hadoop2.7/python/lib
ls -r
在这里插入图片描述
source .bash_profile 生效环境变量

然后进入python

from pyspark import SparkContext
from pyspark import SparkConf
conf = SparkConf().setMaster("local[*]").setAppName("test") 
sc = SparkContext.getOrCreate(conf)
# sc = SparkContext( 'local', 'test')   这种写法也可以

在这里插入图片描述

textFile = sc.textFile("file:///home/You Have Only One Life.txt")
wordCount = textFile.flatMap(lambda line: line.split(" ")).map(lambda word: (word,1)).reduceByKey(lambda a, b : a + b)
wordCount.foreach(print)

在这里插入图片描述

sc.stop()
quit()

在这里插入图片描述

下面是wordcount所用到的文章
You Have Only One Life.txt
There are moments in life when you miss someone so much that you just want to pick them from your dreams and hug them for real! Dream what you want to dream;go where you want to go;be what you want to be,because you have only one life and one chance to do all the things you want to do.
May you have enough happiness to make you sweet,enough trials to make you strong,enough sorrow to keep you human,enough hope to make you happy Always put yourself in others’shoes.If you feel that it hurts you,it probably hurts the other person, too.
The happiest of people don’t necessarily have the best of everything;they just make the most of everything that comes along their way.Happiness lies for those who cry,those who hurt, those who have searched,and those who have tried,for only they can appreciate the importance of people
who have touched their lives.Love begins with a smile,grows with a kiss and ends with a tear.The brightest future will always be based on a forgotten past, you can’t go on well in lifeuntil you let go of your past failures and heartaches.
When you were born,you were crying and everyone around you was smiling.Live your life so that when you die,you’re the one who is smiling and everyone around you is crying.
Please send this message to those people who mean something to you,to those who have touched your life in one way or another,to those who make you smile when you really need it,to those that make you see the brighter side of things when you are really down,to those who you want to let them know that you appreciate their friendship.And if you don’t, don’t worry,nothing bad will happen to you,you will just miss out on the opportunity to brighten someone’s day with this message.

文章在本地的路径
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值