我刚刚编写了一个 python 脚本来使用 igraph 模块执行优化模块,这个函数使用了 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())
最佳答案
python-igraph
取决于 igraph 库,它是用 C 编写的。取决于您如何安装 python-igraph
,它可能会或可能不会与 GLPK 支持一起编译。由于使用 GLPK 的代码来自 python-igraph
在C层,编译后安装GLPK没关系python-igraph
或者如果您安装 python-glpk
;唯一重要的是当您编译 python-igraph
时,您的机器上是否存在 GLPK首次。
所以,假设你安装了 python-igraph
使用 pip
并且您的机器上没有预先安装 igraph 的 C 核心,您需要:
python-glpk
(不需要)。 python-igraph
. python-igraph
. python-igraph
然后应该检测到 GLPK 本身已安装(在 GLPK support -- yes
下载相应的 C 内核并尝试编译它的早期阶段查找包含 python-igraph
或类似内容的行),您将能够使用 Graph.optimal_modularity()
从那时起。
关于python - igraph 不能使用 GLPK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28479968/