导入 python-igraph 时出错

Error importing python-igraph

我正在尝试安装 python-igraph 包。安装工作没有任何警告或错误,但是当我尝试导入模块时,出现错误:

In [1]: import igraph
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-8e950eb5d8d8> in <module>()
----> 1 import igraph

/usr/local/lib/python2.7/site-packages/igraph/__init__.py in <module>()
     32 # pylint: disable-msg=W0401
     33 # W0401: wildcard import
---> 34 from igraph._igraph import *
     35 from igraph._igraph import __version__, __build_date__
     36 from igraph.clustering import *

ImportError: dlopen(/usr/local/lib/python2.7/site-packages/igraph/_igraph.so, 2): Library not loaded: /usr/local/opt/gmp/lib/libgmp.10.dylib
  Referenced from: /usr/local/opt/glpk/lib/libglpk.36.dylib
  Reason: Incompatible library version: libglpk.36.dylib requires version 14.0.0 or later, but libgmp.10.dylib provides version 13.0.0

我无法解决这个问题。我看到 并尝试了他们的解决方案,但它没有用(问题是 glpk 没有安装,而我安装了)。

为了安装它,我执行了以下操作:

brew tap homebrew/science
brew install igraph
sudo pip install python-igraph

而且我检查了 gmp 和 glpk 是否安装了 brew install igraph

有人知道我如何设法安装它吗?

我正在研究 Mac os x el capitan,python2.7

感谢您的帮助

从 Tamás 的回答中编辑:

我检查了一下,gmp 和 glpk 确实来自 homebrew。事实上,/usr/local/opt/gmp<path_to_>Cellar/gmp/6.0.0a/usr/local/opt/glpk<path_to_>Cellar/glpk/4.57 的符号链接。

无论如何我都尝试卸载 igraph (brew uninstall igraph),将 /usr/local/opt 中的文件移动到其他地方以获取 gmp 和 glpk,然后重新安装 igraph。但是我在导入 python 模块时遇到了完全相同的错误...

GMP 和 GLPK 似乎不是来自 Homebrew,它们彼此不兼容。您必须修复 GMP 和 GLPK 的安装。或者,您可以卸载 igraph,然后暂时将 GMP 和 GLPK 的目录从 /usr/local/opt 移动到其他地方,然后重新安装 igraphigraph 然后 "think" GLPK 和 GMP 在您的机器上不可用,并在没有 GLPK 和 GMP 支持的情况下自行编译(并禁用一些需要 GLPK 和 GMP 的功能)。

已解决:

感谢您的评论,我意识到,事实上,Homebrew 并没有最新版本的 gmp。 所以,我从 gmp website 下载了最新版本,并且:

  • 已卸载 igraph
  • 从下载的版本安装 gmp
  • 重新安装 igraph

现在可以了,我可以导入 python 包了!