主要方法未执行python3

时间:2017-10-17 10:29:18

标签: python pyspark python-3.6

我有这个程序来计算sample.txt中的单词:

import os

from operator import add
from pyspark import SparkContext

os.environ["SPARK_HOME"] = "/usr/local/spark"
os.environ["PYSPARK_PYTHON"]="/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6"

print("Hello World") #This is printed

if __name__ == "__main__":
    sc = SparkContext(appName="PythonWordCount")
    lines = sc.textFile("sample.txt", 1)
    counts = lines.flatMap(lambda x: x.split(' ')) \
        .map(lambda x: (x, 1)) \
        .reduceByKey(add)
    output = counts.collect()
    for (word, count) in output:
        print("%s: %i" % (word, count))

    sc.stop()

但似乎该程序没有运行主要的if句子。我是python的新编程,代码中是否有任何错误?

这是我执行代码时的输出(注意" Hello World"打印并且代码编译正确): enter image description here

0 个答案:

没有答案