在 Windows 上使用 Spark-Submit 时“未找到 Python,但可以安装”

NFC*_*NFC 8 python apache-spark pyspark

我按照此处描述的步骤在 Windows 上安装了 PySpark ,Spark 版本为 3.1.2,包类型为 Apache Hadoop 2.7 预构建,而 python 版本为 3.9.6。

我想尝试使用 wordcount 示例进行 Spark-submit,因此我转到 SPARK_HOME 目录中的命令提示符并输入了以下内容:

 bin\spark-submit examples\src\main\python\wordcount.py README.md
Run Code Online (Sandbox Code Playgroud)

但是,我收到了这样的消息:

Python was not found but can be installed from the Microsoft Store: ms-windows-store://pdp/?productid=9NJ46SX7X90P 
Run Code Online (Sandbox Code Playgroud)

我不知道出了什么问题,我确保 Python 在安装时已添加到 PATH 中,并且命令 bin\pyspark 似乎也可以正常工作。我还尝试转到“设置”>“应用程序”>“应用程序执行别名”并禁用所有 python 选项,但它不起作用。

编辑:这是如果我尝试应用程序执行别名方法时收到的错误消息:

Exception in thread "main" java.io.IOException: Cannot run program "python3": CreateProcess error=2, The system cannot find the file specified
        at java.lang.ProcessBuilder.start(Unknown Source)
        at org.apache.spark.deploy.PythonRunner$.main(PythonRunner.scala:97)
        at org.apache.spark.deploy.PythonRunner.main(PythonRunner.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52)
        at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:951)
        at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:180)
        at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:203)
        at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:90)
        at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:1039)
        at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:1048)
        at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
        at java.lang.ProcessImpl.create(Native Method)
        at java.lang.ProcessImpl.<init>(Unknown Source)
        at java.lang.ProcessImpl.start(Unknown Source)
        ... 15 more
Run Code Online (Sandbox Code Playgroud)

Far*_*han 10

已经晚了,但这是解决方案。


  1. 输入环境变量进入environment variables窗口search

在此输入图像描述

  1. 创建一个新environment variable变量,其变量名称等于PYSPARK_PYTHON且值为python

在此输入图像描述

  1. 检查解决方案是否有效?

正如您在启动后所看到的PySpark,仅在能够检测到a.take()时才起作用PySparkPython

在此输入图像描述

或者您也可以通过运行wordcount.py使用command您提到的文档中显示的内容来确认。

C:\spark-3.3.0-bin-hadoop3>bin\spark-submit examples\src\main\python\wordcount.py README.md
Run Code Online (Sandbox Code Playgroud)

这是上述命令的输出,即counting words in a file

22/06/24 11:53:33 INFO SparkContext: Running Spark version 3.3.0

...

guide](https://spark.apache.org/contributing.html): 1
information: 1
get: 1
started: 1
contributing: 1
project.: 1

...
Run Code Online (Sandbox Code Playgroud)