我想在PySpark上使用GraphFrames (目前在Google Dataproc上使用Spark v2.3.3 )。
使用安装了GraphFrames之后
pip install graphframes我尝试运行以下代码:
from graphframes import *
localVertices = [(1,"A"), (2,"B"), (3, "C")]
localEdges = [(1,2,"love"), (2,1,"hate"), (2,3,"follow")]
v = sqlContext.createDataFrame(localVertices, ["id", "name"])
e = sqlContext.createDataFrame(localEdges, ["src", "dst", "action"])
g = GraphFrame(v, e)但是我得到了这个错误:
Py4JJavaError: An error occurred while calling o301.loadClass.
: java.lang.ClassNotFoundException: org.graphframes.GraphFramePythonAPI
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
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)有什么办法解决这个问题吗?
发布于 2019-09-24 09:35:30
要将GraphFrames与Spark一起使用,您应该将其安装为Spark package,而不是PIP包:
pyspark --packages graphframes:graphframes:0.7.0-spark2.3-s_2.11发布于 2019-09-25 15:22:55
如果您正在使用Jupyter进行开发,请从pyspark启动它,而不是直接从Anaconda启动。意思是打开终端,然后运行
export PYSPARK_DRIVER_PYTHON=jupyter
export PYSPARK_DRIVER_PYTHON_OPTS=notebook
pyspark --packages graphframes:graphframes:0.6.0-spark2.3-s_2.11这将启动Jupyter,并在后台加载正确的PySpark包。如果您随后使用from graphframes import将其导入脚本中,它将正确提取并运行
https://stackoverflow.com/questions/58068469
复制相似问题