我刚刚写了一个python脚本来使用igraph模块来做optimal_modularity,这个函数使用了GLPK库,但是即使在安装了python-glpk和几乎所有与glpk相关的包之后,我也得到了这个错误:
root@ubuntu:/home/abdou/Desktop/graphs# python graph.py
Traceback (most recent call last):
File "graph.py", line 49, in <module>
print g.community_optimal_modularity()
File "/usr/lib/python2.7/dist-packages/igraph/__init__.py", line 1076, in community_optimal_modularity
GraphBase.community_optimal_modularity(self, *args, **kwds)
NotImplementedError: Error at optimal_modularity.c:81: GLPK is not available, Unimplemented function call
脚本是这样的:
from igraph import *
g = Graph()
g.add_vertex(1)
.
.
.
g.add_vertex(20)
g.add_edge(1,2)
g.add_edge(12,0)
plot(g)
print g.community_optimal_modularity()
verClus = VertexClustering(g)
plot(verClus.cluster_graph())
发布于 2015-02-12 23:42:18
GLPK依赖于用C编写的igraph库,这取决于您安装python-igraph
的方式,它可能会被编译,也可能不会被编译。由于使用来自python-igraph
的GLPK的代码位于C层,因此无论您是在编译python-igraph
之后安装GLPK还是安装python-glpk
,唯一重要的是当您第一次编译python-igraph
时,您的机器上是否存在GLPK。
因此,假设您使用pip
安装了python-igraph
,并且您的机器上事先没有安装igraph的C核心,那么您将需要:
GLPK卸载GLPK库(确保以well).
python-igraph
.的身份安装
python-glpk
(确保将开发头文件安装为GLPK然后,python-igraph
应该检测到安装了GLPK本身(当python-igraph
下载相应的C核心并尝试编译它时,在早期阶段查找包含GLPK support -- yes
或类似内容的行),从那时起,您就可以使用Graph.optimal_modularity()
了。
发布于 2019-05-09 03:15:12
我正在使用聚类方法,并获得成员资格。希望这能对MacOS用户有所帮助,因为我也遇到过GLPK的问题。
https://stackoverflow.com/questions/28479968
复制相似问题