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

4.6k views Asked by At

I am trying to install pygraphviz on my 64-bit installation of Windows 7 SP1. I was able to get the usual python setup.py install command to work by correcting the following lines of the setup.py file:

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. If I go to that directory and try to import it, I get a different 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). I can't find any other instances of this problem from other pygraphviz users. What am I doing wrong?

1

There are 1 answers

1
WGS On BEST ANSWER

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.

  1. Download and install Graphviz 2.38 from here.
  2. Download the binary installer for pygraphviz from here. Use the appropriate version (pygraphviz‑1.2.win‑amd64‑py2.7.exe). Install. Make sure the installer detects your correct PYTHONPATH.

Result:

enter image description here