"""SimpleApp"""
from pyspark import SparkContext
from pyspark.streaming.kafka import KafkaUtils
logFile = "C:\spark-2.1.0-bin-hadoop2.7\README.md"
sc = SparkContext("local","Simple App")
logData = sc.textFile(logFile).cache()
numAs = logData.filter(lambda s: 'a' in s).count()
numBs = logData.filter(lambda s: 'b' in s).count()
print("Lines with a: %i, lines with b: %i"%(numAs, numBs))
本人运行这个没有问题。但是运行basic.py直接报错
C:\Users\John\AppData\Local\Programs\Python\Python35\python.exe C:/Users/John/PycharmProjects/hellworld/test2.py
Traceback (most recent call last):
File "C:/Users/John/PycharmProjects/hellworld/test2.py", line 218, in <module>
basic_df_example(spark)
File "C:/Users/John/PycharmProjects/hellworld/test2.py", line 45, in basic_df_example
df = spark.read.json("C:\spark-2.1.0-bin-hadoop2.7\examples\src\main\resources\people.json")
AttributeError: 'function' object has no attribute 'read'
Process finished with exit code 1
|
|