我使用 pyspark 创建了一个数据框,但无法查看使用
.show()
创建的数据。
我遇到了 Py4JJavaError
我安装了findspark,在使用时
findspark.init()
我收到以下错误
IndexError Traceback (most recent call last)
File c:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\findspark.py:159, in init(spark_home, python_path, edit_rc, edit_profile)
158 try:
--> 159 py4j = glob(os.path.join(spark_python, "lib", "py4j-*.zip"))[0]
160 except IndexError:
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
c:\Users\user\Documents\Python Programming\PySpark_for_Big_Data.ipynb Cell 3 line 1
----> 1 findspark.init()
File c:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\findspark.py:161, in init(spark_home, python_path, edit_rc, edit_profile)
159 py4j = glob(os.path.join(spark_python, "lib", "py4j-*.zip"))[0]
160 except IndexError:
--> 161 raise Exception(
162 "Unable to find py4j in {}, your SPARK_HOME may not be configured correctly".format(
163 spark_python
164 )
165 )
166 sys.path[:0] = sys_path = [spark_python, py4j]
167 else:
168 # already imported, no need to patch sys.path
Exception: Unable to find py4j in C:\Windows\system32\config\systemprofile\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyspark\python, your SPARK_HOME may not be configured correctly
我的环境变量设置是: HADOOP_HOME:C:\hadoop SPARK_HOME:%USERPROFILE%\ AppData \ Local \ Programs \ Python \ Python312 \ Lib \ site-packages \ pyspark JAVA_HOME: C:\Program Files\Java\jdk-20 SPARK_LOCAL_IP:127.0.0.1 PYTHONPATH:%SPARK_HOME%\python;%SPARK_HOME%\python\lib\py4j-0.10.9.7-src.zip 路径:%HADOOP_HOME% 在 %SPARK_HOME% 位于
我的Java版本:java 20.0.2 2023-07-18 我的Python版本:Python 3.12.0 我的Spark版本:Spark 3.5.1 VS Code IDE 中使用的 Python 内核:%USERPROFILE%\AppData\Local\Programs\Python\Python312\python.exe
请指教。我很绝望。
Error Index out of range at
[0]
表示空列表,这意味着您的 glob 尝试失败。os.path.isdir()
或您知道文件应该在的位置上的 os.path.isfile()
等工具验证您的路径。