16

I see many questions on the difficulties of properly installing pygraphviz and graphviz on Windows for Python 2.7. But no answers that I have found is solving my problem. Here's what I did:

  • I first installed pygraphviz using unofficial windows binaries with this link in my anaconda (python) folder ( C:\Users\chamar\AppData\Local\Continuum\Anaconda )
  • Downloaded graphviz-2.36.msi and installed it under the default path C:\Program Files (x86)\Graphviz2.36

The command import pygraphviz in Python works. But when I want to use say this function nx.graphviz_layout I get raise ValueError("Program %s not found in path."%prog)

What may cause this problem is that pygraphviz cannot locate the path of graphviz. Now, since I installed pygraphviz using the unofficial windows binary, which file can I modify to link both the library and include for graphviz's path? You would you usually find in the setup.py of pygraphviz the library and include paths when you don't use the unofficial binaries.

UPDATE 1

I added to PATH in Regedit under SOFTWARE a folder GRAPHIZ with a new key (default) with value C:\Program Files (x86)\Graphviz2.36\bin

UPDATE 2

I was having an error in the pydot.py file regarding the difficulty of Python locating the path of Graphviz. I made the changes as follow:

def _graphviz():
    if os.sys.platform == 'win32':
        path = r"C:/Program Files (x86)/Graphviz2.36/bin/"
        progs = __find_executables(path)
        return progs

find_graphviz()
{'fdp': 'C:/Program Files (x86)/Graphviz2.36/bin/fdp.exe', 'twopi': 'C:/Program Files (x86)/Graphviz2.36/bin/twopi.exe', 'neato': 'C:/Program Files (x86)/Graphviz2.36/bin/neato.exe', 'dot': 'C:/Program Files (x86)/Graphviz2.36/bin/dot.exe', 'circo': 'C:/Program Files (x86)/Graphviz2.36/bin/circo.exe'}

That seems ok with me but when I execute say:

positions = nx.graphviz_layout(G, prog='twopi', root=0)

I get:

    Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\chamar.stu\AppData\Local\Continuum\Anaconda\lib\site-packages\networkx\drawing\nx_agraph.py", line 229, in graphviz_layout
    return pygraphviz_layout(G,prog=prog,root=root,args=args)
  File "C:\Users\chamar.stu\AppData\Local\Continuum\Anaconda\lib\site-packages\networkx\drawing\nx_agraph.py", line 264, in pygraphviz_layout
    A.layout(prog=prog,args=args)
  File "C:\Users\chamar.stu\AppData\Local\Continuum\Anaconda\lib\site-packages\pygraphviz\agraph.py", line 1305, in layout
    data=self._run_prog(prog,' '.join([args,"-T",fmt]))
  File "C:\Users\chamar.stu\AppData\Local\Continuum\Anaconda\lib\site-packages\pygraphviz\agraph.py", line 1251, in _run_prog
    runprog=r'"%s"'%self._get_prog(prog)
  File "C:\Users\chamar.stu\AppData\Local\Continuum\Anaconda\lib\site-packages\pygraphviz\agraph.py", line 1239, in _get_prog
    raise ValueError("Program %s not found in path."%prog)
ValueError: Program twopi not found in path.

Why?

Plug4
  • 3,258
  • 7
  • 40
  • 70
  • 1
    geotheory's comment from http://stackoverflow.com/questions/2798858/installing-pygraphviz-on-windows-python-2-6 solved the problem for me...it works – user2543622 Mar 28 '14 at 23:46
  • When I add: `library_path=r"C:\Program Files (x86)\Graphviz2.36\bin" include_path=r"C:\Program Files (x86)\Graphviz2.36\include\graphviz"` I always get as an error `Import error: No Module named Release` when I execute `python setup.py build -c mingw32` – Plug4 Mar 29 '14 at 00:14

3 Answers3

13

Here are the steps I followed to get pygraphviz working for Python 3.4 (I think if you follow the analogous steps, it should work for Python 2.x). I'm just documenting it here for future visitors to the page :

Pre-requisites :

  1. wheel (Should be present by default in newer distributions)
  2. The correct Windows build of pygraphviz (unofficial builds). On Win7 x64, I selected "pygraphviz‑$version-cp34‑none‑win_amd64.whl". (Note the cp34 indicating the python version.)
  3. The Graphviz installer version 2.38 (for which the above wheel is built)

Steps:

  1. Run the Graphviz installer
  2. Add the Graphviz\bin folder to your user or system PATH
  3. Check: Open a command prompt and execute twopi -V. You should be able to see the Graphviz version printed onto the console.
  4. Now go to your Python environment (e.g. by running anaconda.bat, a prompt where you can run python)
  5. Run pip install pygraphviz‑*$version*-cp34‑none‑win_amd64.whl
  6. You're done :) ! Run an example script to see if everything went well.
makrasnov100
  • 39
  • 1
  • 7
StudioEvoque
  • 882
  • 2
  • 9
  • 13
  • 1
    Good guide. Running Anaconda 2.3, Python 2.7.10, on Windows 8.1. No need to install wheel. – rll Oct 01 '15 at 12:40
  • example script is gone. :( – szeitlin Sep 26 '16 at 20:42
  • 1
    At the time of writing, the unofficial binaries page still doesn't have a Python 3.5 version available, which is a shame. Python 3.5 is over a year old. – Oddthinking Nov 09 '16 at 01:05
  • @StudioEvoque I am facing the same problem with a mac, do you know how to solve the problem ? – Jb_Eyd Jan 18 '17 at 13:05
  • Wow, finally found a 64 bit wheel for pygraphviz and then see it is python3.4 while I've already fought this same type of thing with half-dozen other libraries that I need, using python 3.5. This graphviz build ecosystem is a nightmare. Hope someone takes on replacing it as a side project. – Bob Jordan Mar 08 '17 at 01:46
0

You'll find loads of install-ready packages on this site: http://www.lfd.uci.edu/~gohlke/pythonlibs/ including the ones you tried to install. I know I'm way too late with the answer but I just became a member.

implicati0n
  • 259
  • 2
  • 9
-1

You may first install "easy_install" (look at How to use Python's "easy_install" on Windows ... it's not so easy) then 2 packages are required: 'python-pygraph' & 'libgv-python'.

Community
  • 1
  • 1
A STEFANI
  • 6,434
  • 1
  • 21
  • 41