在Windows 7上安装了pygraphviz,但无法导入它;无法找到_graphviz

时间:2014-11-13 16:52:00

标签: python graphviz pygraphviz

我正在尝试在我的64位Windows 7 SP1安装上安装pygraphviz。我通过更正python setup.py install文件的以下行来获得通常的setup.py命令:

include_dirs = r"C:\Program Files (x86)\Graphviz2.38\include"
library_dirs = r"C:\Program Files (x86)\Graphviz2.38\lib\release\lib"

但是当我尝试导入它时,我收到以下错误:

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygraphviz
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pygraphviz\__init__.py", line 58, in <module>
    from .agraph import AGraph, Node, Edge, Attribute, ItemAttribute
  File "pygraphviz\agraph.py", line 26, in <module>
    from . import graphviz as gv
  File "pygraphviz\graphviz.py", line 28, in <module>
    _graphviz = swig_import_helper()
  File "pygraphviz\graphviz.py", line 20, in swig_import_helper
    import _graphviz
ImportError: No module named _graphviz

这很令人费解,因为安装的目录pygraphviz确实包含_graphviz.pyd文件。如果我转到该目录并尝试导入它,我会得到一个不同的ImportError:

C:\Python27\Lib\site-packages\pygraphviz>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import _graphviz
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.

据我所知,_graphviz.pyd文件似乎编译不当(我正在使用mingw32,相应地编辑了我的distutils.cfg文件)。我从其他pygraphviz用户中找不到此问题的任何其他实例。我做错了什么?

1 个答案:

答案 0 :(得分:7)

这是我为完美的安装工作所做的。在Windows 64位SP1上使用Anaconda发行版运行Python 2.7.8。

  1. here下载并安装Graphviz 2.38
  2. here下载pygraphviz的二进制安装程序。使用适当的版本(pygraphviz‑1.2.win‑amd64‑py2.7.exe)。安装。确保安装程序检测到正确的PYTHONPATH
  3. 结果:

    enter image description here