【问题标题】:Errors in Eclipse executing Python program using Spark libraryEclipse 使用 Spark 库执行 Python 程序时出错
【发布时间】:2018-03-18 10:00:27
【问题描述】:

我正在按照本教程here 使用 Spark 库为 python 编程配置 eclipse。我一步一步地跟着没有任何问题...

但是,一旦我执行了这个示例程序:

# Imports
# Take care about unused imports (and also unused variables),
# please comment them all, otherwise you will get any errors at the execution.
# Note that neither the directives "@PydevCodeAnalysisIgnore" nor "@UnusedImport"
# will be able to solve that issue.
#from pyspark.mllib.clustering import KMeans
from pyspark import SparkConf, SparkContext
import os

# Configure the Spark environment
sparkConf = SparkConf().setAppName("WordCounts").setMaster("local")
sc = SparkContext(conf = sparkConf)

     # The WordCounts Spark program
    textFile = sc.textFile(os.environ["SPARK_HOME"] + "/README.md")
    wordCounts = textFile.flatMap(lambda line: line.split()).map(lambda word: (word, 1)).reduceByKey(lambda a, b: a+b)
    for wc in wordCounts.collect(): print wc

我得到一个这样的错误列表:

我是否必须修改任何路径或遵循其他配置才能使其工作?

【问题讨论】:

    标签: python windows eclipse apache-spark


    【解决方案1】:

    如果您在保存自述文件的同一目录中运行 pyspark shell,则无需提供 spark 主路径。

    尝试删除 spark home 路径和“/”。

    textFile = sc.textFile("README.md")
    

    textFile = sc.textFile(os.environ["SPARK_HOME"] + "README.md").
    

    定义拆分条件。空格分隔或 '#' 任何值分隔的拆分

    lambda line: line.split(" ")
    

    【讨论】:

      猜你喜欢
      • 2020-04-17
      • 2011-08-02
      • 2018-01-13
      • 1970-01-01
      • 2020-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-24
      相关资源
      最近更新 更多