简体   繁体   English

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

[英]Installed pygraphviz on Windows 7, but unable to import it; can't find _graphviz

I am trying to install pygraphviz on my 64-bit installation of Windows 7 SP1. 我试图在Windows 7 SP1的64位安装上安装pygraphviz。 I was able to get the usual python setup.py install command to work by correcting the following lines of the setup.py file: 通过更正setup.py文件的以下几行,我能够使通常的python setup.py install命令起作用:

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

When I try to import it, though, I get the following error: 但是,当我尝试导入它时,出现以下错误:

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

This is puzzling because the directory pygraphviz gets installed to does contain a _graphviz.pyd file. 令人费解的是,安装目录pygraphviz确实包含_graphviz.pyd文件。 If I go to that directory and try to import it, I get a different ImportError: 如果我转到该目录并尝试导入它,则会收到另一个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.

So as far as I can tell, the _graphviz.pyd file seems to have been improperly compiled (I am using mingw32, having edited my distutils.cfg file accordingly). 据我所知,_graphviz.pyd文件似乎未正确编译(我使用的是mingw32,已相应编辑了distutils.cfg文件)。 I can't find any other instances of this problem from other pygraphviz users. 我无法从其他pygraphviz用户那里找到此问题的任何其他实例。 What am I doing wrong? 我究竟做错了什么?

Here's what I did for a perfectly working install. 这是我为完美运行安装所做的。 Running Python 2.7.8 using the Anaconda distribution on Windows 64-bit SP1 as well. 在Windows 64位SP1上也使用Anaconda发行版运行Python 2.7.8。

  1. Download and install Graphviz 2.38 from here . 这里下载并安装Graphviz 2.38
  2. Download the binary installer for pygraphviz from here . 此处下载pygraphviz的二进制安装程序。 Use the appropriate version ( pygraphviz‑1.2.win‑amd64‑py2.7.exe ). 使用适当的版本( pygraphviz‑1.2.win‑amd64‑py2.7.exe )。 Install. 安装。 Make sure the installer detects your correct PYTHONPATH . 确保安装程序检测到正确的PYTHONPATH

Result: 结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM