English 中文(简体)
Pyspark - 无法在 Windows 11 上使用 df.show () 显示 DataFrame 内容
原标题:Pyspark - Unable to display the DataFrame contents using df.show() on Windows 11

我跟踪了官方文件 在本地视窗11的机器上 设置了阿帕奇公园

这一设置包括:

  1. Proper installation of Apache Spark, setting up the env variables etc.
  2. Creation of a virtual env specifically for Python 3.9 to ensure compatibility with PySpark.

Despite these steps, I m encountering a ShowString error in VS Code: While I can initiate a Spark session successfully and it starts without errors, I run into problems when trying to use df.show() to display DataFrame contents. The method fails and returns a ShowString error.

不知道目前版本的 java17 space3.5 是否支持 Win11 的表演 。

但任何建议都受到高度赞赏:)

[enter image description here](https://i.sstatic.net/2fBDWU3M.png)
[enter image description here](https://i.sstatic.net/3mjFNGlD.png)
[enter image description here](https://i.sstatic.net/gTm3ecIz.png)

我尝试过多个调试步骤- 验证当前信封变量是否被指向, 并确保火花会话启动 。

问题回答

错误消息 :

--------------------------------------------------------------------------- Py4JJavaError                             Traceback (most recent call last)
Cell In[45], line 2
      1 df = spark.createDataFrame([(1,  Alice ), (2,  Bob )], [ id ,  name ])
----> 2 df.show()

File c:UsersDocumentspyspark_venvlibsite-packagespysparksqldataframe.py:945, in DataFrame.show(self, n, truncate, vertical)
    885 def show(self, n: int = 20, truncate: Union[bool, int] = True, vertical: bool = False) -> None:
    886     """Prints the first ``n`` rows to the console.
    887 
    888     .. versionadded:: 1.3.0
   (...)
    943     name | Bob
    944     """
--> 945     print(self._show_string(n, truncate, vertical))

File c:UsersDocumentspyspark_venvlibsite-packagespysparksqldataframe.py:963, in DataFrame._show_string(self, n, truncate, vertical)
    957     raise PySparkTypeError(
    958         error_class="NOT_BOOL",
    959         message_parameters={"arg_name": "vertical", "arg_type": type(vertical).__name__},
    960     )
    962 if isinstance(truncate, bool) and truncate:
--> 963     return self._jdf.showString(n, 20, vertical)
    964 else:
    965     try:
...
    at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:499)
    at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:158)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)
    ... 34 more

并意识到SparkEnv基本上是在寻找一个 python3 可执行文件

  • creating an alias of python3.exe using python.exe and explicitly specifying in the python path helped.
import os
from pyspark.sql import SparkSession

# Define the Python executable path or alias
python_path = r C:Users\AppDataLocalProgramsPythonPython39python3.exe   
os.environ[ PYSPARK_PYTHON ] = python_path
os.environ[ PYSPARK_DRIVER_PYTHON ] = python_path

spark = SparkSession.builder 
    .appName("Your App Name") 
    .config("spark.python.worker.exec", python_path) 
    .getOrCreate()

df = spark.createDataFrame([(1,  Alice ), (2,  Bob )], [ id ,  name ])
df.show()

+---+-----+
| id| name|
+---+-----+
|  1|Alice|
|  2|  Bob|
+---+-----+




相关问题
VS Code run selection in terminal creating multiple shells

Running selection/line in terminal (shift + enter) started creating opening two shells. The first shell runs commands to activate the environment and start python. The second shell runs the python ...

从案卷中获取简单明朗戈功能——现在可以提供

如果你想到,在纽瓦特被点击之后,如何把服务器的辅助功能从javascript文档中打上下面的几页。 你们必须利用吉大港山区开发计划的要求,把服务器的侧端点称作终端点。 ......

在《科索沃法典》中是否有办法进行沙尘处理

目前,开始学习基因图像处理,我希望在民主选举学会之外使用这种图像,使之更容易编码,因为在处理民主选举学会时,没有很好地掌握合成物的错误。 I ......

Rust Visual Studio Code code completion not working

I m trying to learn Rust and installed the Rust extension for VSCode. But I m not seeing auto-completions for any syntax. I d like to call .trim() on String but I get no completion for it. I read that ...

热门标签