0

我刚刚编写了一个 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())
4

2 回答 2

2

python-igraph取决于 igraph 库,它是用 C 编写的。根据您的安装方式python-igraph,它可能会可能不会使用 GLPK 支持进行编译。由于使用 GLPK from 的代码在 C 层,所以编译python-igraph安装 GLPK还是安装; 唯一重要的是当您第一次编译时,您的机器上是否存在 GLPK。python-igraphpython-glpk python-igraph

因此,假设您python-igraph使用安装pip并且您的机器上没有预先安装 igraph 的 C 核心,您将需要:

  1. 卸载python-glpk(不需要)。
  2. 卸载python-igraph
  3. 确保安装了所有 GLPK 库(确保也安装了开发头文件)。
  4. 重新安装python-igraph

python-igraphGLPK support -- yes然后应该检测到 GLPK 本身已安装(在下载相应的 C 内核并尝试编译它的早期阶段寻找包含或类似内容的行python-igraph),然后您就可以使用Graph.optimal_modularity()了。

于 2015-02-12T15:42:18.290 回答
0

我正在使用聚类方法并获得会员资格。希望这可能对 MacOS 用户有所帮助,因为我也遇到了 GLPK 问​​题。

于 2019-05-08T19:15:11.950 回答