您好,登錄后才能下訂單哦!
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)
計算成功即可
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。