发布时间:2019-08-31 09:43:33编辑:auto阅读(1434)
1、下载如下
放在D盘
添加 SPARK_HOME = D:\spark-2.3.0-bin-hadoop2.7。
找到pycharm sitepackage目录
右键点击即可进入目录,将上面D:\spark-2.3.0-bin-hadoop2.7里面有个/python/pyspark目录拷贝到上面的 sitepackage目录
安装 py4j
试验如下代码:
from __future__ import print_function
import sys
from operator import add
import os
# Path for spark source folder
os.environ['SPARK_HOME'] = "D:\spark-2.3.0-bin-hadoop2.7"
# Append pyspark to Python Path
sys.path.append("D:\spark-2.3.0-bin-hadoop2.7\python")
sys.path.append("D:\spark-2.3.0-bin-hadoop2.7\python\lib\py4j-0.9-src.zip")
from pyspark import SparkContext
from pyspark import SparkConf
if __name__ == '__main__':
inputFile = "D:\Harry.txt"
outputFile = "D:\Harry1.txt"
sc = SparkContext()
text_file = sc.textFile(inputFile)
counts = text_file.flatMap(lambda line: line.split(' ')).map(lambda word: (word, 1)).reduceByKey(lambda a, b: a + b)
counts.saveAsTextFile(outputFile)
计算成功即可
上一篇: k3cloud新建简单帐表教程
下一篇: python关于conda创建新环境
47873
46438
37325
34767
29339
26002
24953
19971
19571
18065
5813°
6438°
5954°
5980°
7086°
5932°
5973°
6463°
6430°
7809°