导入 igraph 时出错

error importing igraph

在 python 中导入 igraph 时出现错误(见下文)。由于 igraph 不是 anaconda 的一部分,我执行了下面概述的安装步骤。

什么是libglpk.35.dylib,我应该如何加载它,为什么会出现这个问题?

无法导入 igraph

'' import igraph
'' Traceback (most recent call last):
''   File "<stdin>", line 1, in <module>
''   File "/Users/claushaslauer/anaconda/lib/python2.7/site-packages/igraph/__init__.py", line 34, in <module>
    '' from igraph._igraph import *
'' ImportError: dlopen(/Users/claushaslauer/anaconda/lib/python2.7/site-packages/igraph/_igraph.so, 2): Library not loaded: /usr/local/lib/libgmp.10.dylib
''   Referenced from: /usr/local/lib/libglpk.35.dylib
''   Reason: image not found

安装步骤

  1. 通过 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. 安装自制软件
  3. 安装 pkg-config(通过 igraph-helpbrew install pkg-config
  4. 通过自制软件安装 igraph:brew install igraph
  5. link: brew install homebrew/science/igraph
  6. pip install python-igraph

遵循 Evert 的建议:

  1. brew uninstall igraph
  2. brew uninstall gmp
  3. brew uninstall glkp -- Error: No such keg: /usr/local/Cellar/glkp
  4. brew install igraph

    ==> 从 homebrew/homebrew-science 安装 igraph ==> 安装 igraph 依赖项:gmp ==> 正在下载 https://homebrew.bintray.com/bottles/gmp-6.0.0a.yosemite.bottle。 已下载:/Library/Caches/Homebrew/gmp-6.0.0a.yosemite.bottle.tar.gz ==> 浇注 gmp-6.0.0a.yosemite.bottle.tar.gz 错误:brew link 步骤未成功完成 公式已构建,但未被 symlinked 到 /usr/local 无法 symlink include/gmp.h 目标 /usr/local/include/gmp.h 已经存在。您可能想要删除它: rm '/usr/local/include/gmp.h'

    强制 link 并覆盖所有冲突文件: brew link --overwrite gmp

    列出所有将被删除的文件: brew link --overwrite --dry-运行 gmp

    可能的冲突文件是: /usr/local/include/gmp.h /usr/local/库/libgmp.a ==> 总结 /usr/local/Cellar/gmp/6.0.0a: 15 个文件,3.2M ==> 安装 igraph ==> 正在下载 https://homebrew.bintray.com/bottles-science/igraph-0.7.1.yosemi 已下载:/Library/Caches/Homebrew/igraph-0.7.1.yosemite.bottle.tar.gz ==>浇注igraph-0.7.1.yosemite.bottle.tar.gz /usr/local/Cellar/igraph/0.7.1: 83 个文件,6.4M

    • "Error: The brew link step did not complete successfully"是什么意思?
    • 我没有看到与 /usr/local/lib/libglpk.35.dylib 相关的任何内容 -- 当我现在调用 python 时,出现了与以前相同的错误。

在 Evert 的帮助下解决

感谢 Evert 的补充回答。有了这些内容,我现在可以导入 igraph 了。需要注意的三点:

  1. 当我说 brew tap homebrew/sciene,使用我的 github 凭据登录时,我得到

    remote: Repository not found.
    fatal: repository 'https://github.com/Homebrew/homebrew-sciene/' not found
    Error: Failure while executing: git clone https://github.com/Homebrew/homebrew-sciene /usr/local/Library/Taps/homebrew/homebrew-sciene --depth=1 
    

    我不确定这有多重要,事实证明,没有这个我也可以 运行 igraph。但是,URL https://github.com/Homebrew/homebrew-sciene/ 为我产生了 404 错误。

  2. brew search glpkbrew search igraph 都是 return 指向 homebrew/science/...

  3. 的一行输出
  4. brew link --overwrite gmp 说它创建了 11 个 symlink。我认为这就是解决我的问题的原因,所以现在我可以在 python.

  5. 中正常导入 igraph

感谢您的帮助。

缺少glpk依赖,因为安装igraph时,只搜索默认包。 glpkigraph 一样生活在一个名为 homebrew/science 的额外自制程序存储库中。您可以通过 "tapping" it:

自动访问该存储库
brew tap homebrew/science

现在,还会搜索此存储库中包含的所有包。要确认,请尝试查看以下两个命令是否仅返回包名称:

brew search glpk

brew search igraph

在重新安装 igraph 之前,您必须解决 gmp 的 link 问题;这只是自制软件在卸载步骤中没有完全卸载 igraph 及其依赖项的结果。为此,您可以按照自制软件的建议:

brew link --overwrite gmp

(您正在用之前仍部分安装的 gmp 包覆盖 gmp 包;它们是相同的,因此不会造成任何伤害。)


现在,您应该可以安装 igraph 了:

brew install igraph

如果这也给出了 warning/error 大约 links,使用与 gmp 相同的 --overwrite 选项。

如果 brew install igraph 没有安装 glpk(即,您没有看到类似“==> Installing igraph dependency: glpk”的消息),您可以简单地单独安装它:

brew install glpk

提供或接受一些次要细节,您现在应该可以安装 igraph(并且,由于您从未卸载 python-igraph,因此它应该仍然可以工作)。