【问题标题】:System cannot find the specified route on creating SparkSession with PySpark使用 PySpark 创建 SparkSession 时系统找不到指定的路由
【发布时间】:2020-06-13 22:53:25
【问题描述】:

我正在尝试在 Win10 虚拟机上与 Python 一起学习 Spark。为此,我正在尝试使用 PySpark 从 CSV 文件中读取数据,但会停止以下操作:

C:\Users\israel\AppData\Local\Programs\Python\Python37\python.exe C:/Users/israel/Desktop/airbnb_python/src/main/python/spark_python/airbnb.py

你好世界1

系统找不到指定路线

我已阅读 How to link PyCharm with PySpark? , PySpark, Win10 - The system cannot find the path specified , The system cannot find the path specified error while running pyspark , PySpark - The system cannot find the path specified 但还没有找到实施解决方案的运气。

我正在使用 IntelliJ,python 3.7。这是运行配置。

我正在使用 IntelliJ,python 3.7。代码如下

from pyspark.sql import SparkSession
from pyspark.sql import Row
from pyspark.sql.types import *


if __name__ == "__main__":

    print("hello world1")

    spark = SparkSession \
        .builder \
        .appName("spark_python") \
        .master("local") \
        .getOrCreate()

    print("hello world2")

    path = "C:\\Users\\israel\\Desktop\\data\\listings.csv"

    df = spark.read\
        .format("csv")\
        .option("header", "true")\
        .option("inferSchema", "true")\
        .load(path)

    df.show()

    spark.stop()

似乎错误出现在 SparkSession 中,但我看不出宣布的错误与该行有什么关系。值得一提的是,执行永远不会结束,我必须手动停止执行才能重新运行。谁能告诉我我做错了什么?请

【问题讨论】:

  • 您检查过SPARK_HOME、HADOOP_HOME 和JAVA_HOME 的路径吗?它们都正确吗?
  • 是的,它们是最后一张图片

标签: python apache-spark intellij-idea pyspark


【解决方案1】:

如果错误信息写成sys.stderr

我在这里提供的答案不是针对真正的问题,

但我注意到了你所说的:但我不明白宣布的错误与该行有何关系......

所以我想为您提供调试以查找生成此消息的代码的位置。

根据你airhnb(第一个)的图片,错误信息El sistema no puede encontrar la ruta especificada。 貌似是sys.stderr写的

所以我的方法是重定向sys.stderr,如下:

import sys


def the_process():
    ...
    sys.stderr.write('error message')


class RedirectStdErr:
    def write(self, msg: str):
        if msg == 'error message':
            set_debug_point_at_here = 1
        original.write(msg)
        original.flush()


original = sys.stderr
sys.stderr = RedirectStdErr()

the_process()

只要在set_debug_point_at_here = 1上设置断点,就可以知道真正调用这段代码的地方在哪里。

【讨论】:

    【解决方案2】:

    我确信这不是最好的解决方案,但一种方法是直接从 pyspark 二进制文件启动你的 python 解释器。

    这可以位于: $SPARK_HOME\bin\pyspark

    此外,如果您在任何终端处于活动状态时修改环境变量,则在下次启动之前不会刷新变量。这也适用于 Pycharm。如果你还没有尝试过,重启 pycharm 也可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-14
      • 1970-01-01
      • 2018-08-26
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多