我正在尝试在我的项目中创建pyspark数据框。 我在笔记本上成功完成了操作,但在pycharm项目中无法使用(尽管我已在正确的环境中配置了项目解释器)。
这是简单的代码:
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()
purchase = spark.createDataFrame(pd.DataFrame({"sold": ["1", "1"], "bill": ["2", "2"]}))
我收到以下错误:
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
19/04/16 15:56:39 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
19/04/16 15:56:40 WARN Utils: Service 'SparkUI' could not bind on port 4040. Attempting port 4041.
Error
Traceback (most recent call last):
File "/Users/myself/anaconda3/envs/spark_py35_01/lib/python3.5/unittest/case.py", line 59, in testPartExecutor
yield
File "/Users/myself/anaconda3/envs/spark_py35_01/lib/python3.5/unittest/case.py", line 605, in run
testMethod()
File "/Users/myself/Documents/project/2018-11-05_loreal_datascience/salon-centric-fraud-detection/tests/test_feature_engineering/test_feature_creation.py", line 29, in test_create_feature_analyse_lags_on_shipment_billing_date
purchase = spark.createDataFrame(pd.DataFrame({"sold": ["1", "1"], "bill": ["2", "2"]}))
File "/Users/myself/anaconda3/envs/spark_py35_01/lib/python3.5/site-packages/pyspark/sql/session.py", line 524, in createDataFrame
jdf = self._jsparkSession.applySchemaToPythonRDD(jrdd.rdd(), schema.json())
File "/Users/myself/anaconda3/envs/spark_py35_01/lib/python3.5/site-packages/py4j/java_gateway.py", line 1133, in __call__
answer, self.gateway_client, self.target_id, self.name)
File "/Users/myself/anaconda3/envs/spark_py35_01/lib/python3.5/site-packages/pyspark/sql/utils.py", line 63, in deco
return f(*a, **kw)
File "/Users/myself/anaconda3/envs/spark_py35_01/lib/python3.5/site-packages/py4j/protocol.py", line 319, in get_return_value
format(target_id, ".", name), value)
py4j.protocol.Py4JJavaError: An error occurred while calling o18.applySchemaToPythonRDD.
: java.lang.ClassFormatError: Invalid method Code length 1919247980 in class file scala/reflect/internal/StdCreators$FixedMirrorTypeCreator$
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at scala.reflect.internal.SymbolTable.FixedMirrorTypeCreator$lzycompute(SymbolTable.scala:16)
at scala.reflect.internal.SymbolTable.FixedMirrorTypeCreator(SymbolTable.scala:16)
at scala.reflect.runtime.JavaUniverseForce$class.force(JavaUniverseForce.scala:38)
at scala.reflect.runtime.JavaUniverse.force(JavaUniverse.scala:16)
at scala.reflect.runtime.JavaUniverse.init(JavaUniverse.scala:147)
at scala.reflect.runtime.JavaUniverse.<init>(JavaUniverse.scala:78)
at scala.reflect.runtime.package$.universe$lzycompute(package.scala:17)
at scala.reflect.runtime.package$.universe(package.scala:17)
at org.apache.spark.sql.catalyst.ScalaReflection$.<init>(ScalaReflection.scala:40)
at org.apache.spark.sql.catalyst.ScalaReflection$.<clinit>(ScalaReflection.scala)
at org.apache.spark.sql.catalyst.encoders.RowEncoder$.org$apache$spark$sql$catalyst$encoders$RowEncoder$$serializerFor(RowEncoder.scala:74)
at org.apache.spark.sql.catalyst.encoders.RowEncoder$.apply(RowEncoder.scala:61)
at org.apache.spark.sql.Dataset$.ofRows(Dataset.scala:64)
at org.apache.spark.sql.SparkSession.applySchemaToPythonRDD(SparkSession.scala:701)
at org.apache.spark.sql.SparkSession.applySchemaToPythonRDD(SparkSession.scala:691)
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:280)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:214)
at java.lang.Thread.run(Thread.java:748)
Ran 1 test in 1.937s
FAILED (errors=1)
Process finished with exit code 1
有任何线索吗? (我是否必须在pycharm中的某个位置更改配置?在代码中更改?还是在其他位置?)