我正在尝试在AWS EMR上的Jupyter Notebook的pyspark中使用graphframes软件包(使用Sagemaker和sparkmagic)。在AWS控制台中创建EMR集群时,我尝试添加配置选项:
[{"classification":"spark-defaults", "properties":{"spark.jars.packages":"graphframes:graphframes:0.7.0-spark2.4-s_2.11"}, "configurations":[]}]
但是当尝试在jupyter笔记本的pyspark代码中使用graphframes软件包时,仍然出现错误。
这是我的代码(来自graphframes示例):
# Create a Vertex DataFrame with unique ID column "id"
v = spark.createDataFrame([
("a", "Alice", 34),
("b", "Bob", 36),
("c", "Charlie", 30),
], ["id", "name", "age"])
# Create an Edge DataFrame with "src" and "dst" columns
e = spark.createDataFrame([
("a", "b", "friend"),
("b", "c", "follow"),
("c", "b", "follow"),
], ["src", "dst", "relationship"])
# Create a GraphFrame
from graphframes import *
g = GraphFrame(v, e)
# Query: Get in-degree of each vertex.
g.inDegrees.show()
# Query: Count the number of "follow" connections in the graph.
g.edges.filter("relationship = 'follow'").count()
# Run PageRank algorithm, and show results.
results = g.pageRank(resetProbability=0.01, maxIter=20)
results.vertices.select("id", "pagerank").show()
这是输出/错误:
ImportError: No module named graphframes
我通读了this git thread,但所有可能的解决方法似乎都非常复杂,需要将其切入EMR群集的主节点中。
答案 0 :(得分:4)
上面的答案很好,但现在图形框架的存储库位于 https://repos.spark-packages.org/。因此,为了使其工作,分类应更改为:
[
{
"classification":"spark-defaults",
"properties":{
"spark.jars.packages":"graphframes:graphframes:0.8.0-spark2.4-s_2.11",
"spark.jars.repositories":"https://repos.spark-packages.org/"
}
}
]
答案 1 :(得分:2)
我终于发现有一个PyPi package for graphframes。我用它来创建了一个详细的here自举动作,尽管我做了一些改动。
这是我在EMR上运行图框的方法:
#!/bin/bash
sudo pip install graphframes
[{"classification":"spark-defaults","properties":{"spark.jars.packages":"graphframes:graphframes:0.7.0-spark2.4-s_2.11"}}]
# Create a Vertex DataFrame with unique ID column "id"
v = spark.createDataFrame([
("a", "Alice", 34),
("b", "Bob", 36),
("c", "Charlie", 30),
], ["id", "name", "age"])
# Create an Edge DataFrame with "src" and "dst" columns
e = spark.createDataFrame([
("a", "b", "friend"),
("b", "c", "follow"),
("c", "b", "follow"),
], ["src", "dst", "relationship"])
# Create a GraphFrame
from graphframes import *
g = GraphFrame(v, e)
# Query: Get in-degree of each vertex.
g.inDegrees.show()
# Query: Count the number of "follow" connections in the graph.
g.edges.filter("relationship = 'follow'").count()
# Run PageRank algorithm, and show results.
results = g.pageRank(resetProbability=0.01, maxIter=20)
results.vertices.select("id", "pagerank").show()
这一次,最后,我得到了正确的输出:
+---+--------+
| id|inDegree|
+---+--------+
| c| 1|
| b| 2|
+---+--------+
+---+------------------+
| id| pagerank|
+---+------------------+
| b|1.0905890109440908|
| a| 0.01|
| c|1.8994109890559092|
+---+------------------+