我最近使用anaconda将pyspark从2.4.5更新到2.4.6。但是,当我尝试初始化jupyter笔记本(或以另一种方式运行它)时,以下代码会抛出一个错误,而在更新之前没有:
import pyspark
from pyspark.sql import SparkSession
from pyspark.sql.functions import *
from pyspark.sql.types import *
import pandas as pd
import os, shutil
import numpy as np
import matplotlib.pyplot as pl
os.environ["ARROW_PRE_0_15_IPC_FORMAT"] = "1"
spark = SparkSession.builder \
.master('local[2]') \
.appName('chapter2') \
.config('spark.jars.packages', 'io.delta:delta-core_2.11:0.4.0') \ # <--- here it shows the error
.config('spark.executor.memory','6gb') \
.getOrCreate()
sc = spark.sparkContext
spark.sql("set spark.sql.shuffle.partitions = 1")
错误如下:
---------------------------------------------------------------------------
Py4JJavaError Traceback (most recent call last)
in
20 .appName('chapter2') \
21 .config('spark.jars.packages', 'io.delta:delta-core_2.11:0.4.0') \
---> 22 .config('spark.executor.memory','6gb') \
23 .getOrCreate()
24
~/anaconda3/lib/python3.7/site-packages/pyspark/sql/session.py in getOrCreate(self)
181 session = SparkSession(sc)
182 for key, value in self._options.items():
--> 183 session._jsparkSession.sessionState().conf().setConfString(key, value)
184 for key, value in self._options.items():
185 session.sparkContext._conf.set(key, value)
~/anaconda3/lib/python3.7/site-packages/py4j/java_gateway.py in __call__(self, *args)
1255 answer = self.gateway_client.send_command(command)
1256 return_value = get_return_value(
-> 1257 answer, self.gateway_client, self.target_id, self.name)
1258
1259 for temp_arg in temp_args:
~/anaconda3/lib/python3.7/site-packages/pyspark/sql/utils.py in deco(*a,**kw)
61 def deco(*a,**kw):
62 try:
---> 63 return f(*a,**kw)
64 except py4j.protocol.Py4JJavaError as e:
65 s = e.java_exception.toString()
~/anaconda3/lib/python3.7/site-packages/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
326 raise Py4JJavaError(
327 "An error occurred while calling {0}{1}{2}.\n".
--> 328 format(target_id, ".", name), value)
329 else:
330 raise Py4JError(
Py4JJavaError: An error occurred while calling o34.sessionState.
: java.lang.NoSuchMethodError: org.apache.spark.sql.internal.StaticSQLConf$.DEFAULT_URL_STREAM_HANDLER_FACTORY_ENABLED()Lorg/apache/spark/internal/config/ConfigEntry;
at org.apache.spark.sql.internal.SharedState$.org$apache$spark$sql$internal$SharedState$$setFsUrlStreamHandlerFactory(SharedState.scala:165)
at org.apache.spark.sql.internal.SharedState.(SharedState.scala:45)
at org.apache.spark.sql.SparkSession$$anonfun$sharedState$1.apply(SparkSession.scala:121)
at org.apache.spark.sql.SparkSession$$anonfun$sharedState$1.apply(SparkSession.scala:121)
at scala.Option.getOrElse(Option.scala:121)
at org.apache.spark.sql.SparkSession.sharedState$lzycompute(SparkSession.scala:121)
at org.apache.spark.sql.SparkSession.sharedState(SparkSession.scala:120)
at org.apache.spark.sql.internal.BaseSessionStateBuilder.build(BaseSessionStateBuilder.scala:286)
at org.apache.spark.sql.SparkSession$.org$apache$spark$sql$SparkSession$$instantiateSessionState(SparkSession.scala:1115)
at org.apache.spark.sql.SparkSession$$anonfun$sessionState$2.apply(SparkSession.scala:145)
at org.apache.spark.sql.SparkSession$$anonfun$sessionState$2.apply(SparkSession.scala:144)
at scala.Option.getOrElse(Option.scala:121)
at org.apache.spark.sql.SparkSession.sessionState$lzycompute(SparkSession.scala:144)
at org.apache.spark.sql.SparkSession.sessionState(SparkSession.scala:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Thread.java:748)
我已经卸载了pyspark、pyarrow、py4j、koalas,并更改为最新版本,但我仍然面临同样的问题。如果有人知道会发生什么,能帮助我,我将不胜感激。
暂无答案!
目前还没有任何答案,快来回答吧!