python - igraph 不能使用 GLPK

标签 python ubuntu ubuntu-14.04 igraph glpk

我刚刚编写了一个 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 .
  • 确保安装了所有 GLPK 库(确保也安装了开发头文件)。
  • 重新安装python-igraph .
  • python-igraph然后应该检测到 GLPK 本身已安装(在 GLPK support -- yes 下载相应的 C 内核并尝试编译它的早期阶段查找包含 python-igraph 或类似内容的行),您将能够使用 Graph.optimal_modularity()从那时起。

    关于python - igraph 不能使用 GLPK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28479968/

    相关文章:

    python - 通过ast.literal_eval加载41MB文件会导致MemoryError

    python - django、python、postgres 和 web 部署

    linux - 使用 shell 脚本设置路径变量 - 使用 shell 变量

    ubuntu-14.04 - Lazarus:禁用控制台消息 "WARNING: TGtk2WidgetSet.InvalidateRect refused invalidating"

    python - 如何将 Django 表单嵌入到我的 CSS 设计中?

    python - 更改 CSV 列中的数据格式

    python - 为什么 TravisCI 找不到我的许可证文件?

    linux - 附加到/etc/apt/sources.list

    perl - 如果安装或未安装软件包,在 Ubuntu/Debian 中返回 0 或 1 的软件包管理器命令

    c++ - g++ 即使在安装 apt-get 之后也显示为已安装