Installing pygraphviz on windows

时光怂恿深爱的人放手 提交于 2019-11-27 22:35:15

Here's what worked for me. Precondition: Install mingw32 (included in pythonxy distrib if you're using it), Graphviz

1) Download pygraphviz sources

2) Edit setup.py to change paths to smth like

library_path=r"c:\Program Files (x86)\Graphviz 2.28\bin"
include_path=r"c:\Program Files (x86)\Graphviz 2.28\include\graphviz"

Note that it's \bin, not \lib. Linking with libs didn't work for me.

3) run python setup.py build -c mingw32

Result of step 3:

c:\Python27\Lib\site-packages\pygraphviz-1.1>python setup.py build -c mingw32
library_path=c:\Program Files (x86)\Graphviz 2.28\bin
include_path=c:\Program Files (x86)\Graphviz 2.28\include\graphviz
running build
running build_py
running build_ext
building 'pygraphviz._graphviz' extension
C:\MinGW32-xy\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-Ic:\Program Files (x86)\G
raphviz 2.28\include\graphviz" -Ic:\Python27\include -Ic:\Python27\PC -c pygraph
viz/graphviz_wrap.c -o build\temp.win32-2.7\Release\pygraphviz\graphviz_wrap.o
pygraphviz/graphviz_wrap.c: In function 'agattr_label':
pygraphviz/graphviz_wrap.c:2855:5: warning: return makes integer from pointer wi
thout a cast
writing build\temp.win32-2.7\Release\pygraphviz\_graphviz.def
C:\MinGW32-xy\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.7\Release\py
graphviz\graphviz_wrap.o build\temp.win32-2.7\Release\pygraphviz\_graphviz.def "
-Lc:\Program Files (x86)\Graphviz 2.28\bin" -Lc:\Python27\libs -Lc:\Python27\PCb
uild "-Wl,-Rc:\Program Files (x86)\Graphviz 2.28\bin" -lcgraph -lcdt -lpython27
-lmsvcr90 -o build\lib.win32-2.7\pygraphviz\_graphviz.pyd

4) copy the result from the just built lib.win32-2.7 (single sub-folder called pygraphviz) into your Python's site-packages folder

Enjoy!

for windows 64-bit:

similarly to what Andrew Filev wrote with the exceptions that you NEED to use pythonxy, and you NEED to install Graphviz in a folder that does not contain spaces (including the root folder of the program: "Graphviz 2.28"=> "Graphviz2.28"

so:

1) uninstall python 2.7

2) install pythonxb (http://code.google.com/p/pythonxy/wiki/Downloads)

3) install Graphviz 2.28 (the only one I tested) making sure there are no spaces in the installation path. A good example would be: "C:\Graphviz2.28"

4) download pygraphviz as a zip (the sources) and unzip.

5) modify the setup.py near the top to have

library_path=r"c:\Graphviz2.28\bin"
include_path=r"c:\Graphviz2.28\include\graphviz"

6) run: python setup.py build -c mingw32

7) after seeing this result (much nicer than the one posted earlier):

>python setup.py build -c mingw32
library_path=c:\Graphviz2.28\bin
include_path=c:\Graphviz2.28\include\graphviz
running build
running build_py
running build_ext

copy the result from the just built lib.win32-2.7 (single sub-folder called pygraphviz) into your Python's site-packages folder which you might have to make yourself + bind the new root folder of pygraphviz to the environment variable PYTHONPATH

For example the final library could be situated here:

C:\Python27\libs\site_packages\pygraphviz
Aric

PyGraphviz uses an C language extension module (generated by SWIG). So you need a compiler to build the extension. You might need the same compiler that built your Python executable.

There is some information in this question Building Python C extension modules for Windows

and also at http://www.swig.org/Doc1.3/Python.html#Python_nn12

I just spent half an hour trying to figure out why the answers above weren't working for me and it turns out they are out-of-date as library_path and include_path are no longer the names of the relevant variables. Here's what worked for me on Windows 7, 32-bit Python 2.7:

setup.py

library_dirs = r'C:\PROGRA~2\Graphviz2.38\bin'
include_dirs = r'C:\PROGRA~2\Graphviz2.38\include'

then run python setup.py build -c mingw32

An old question but I've just done this and couldn't find a specific answer for Python 3 and I didn't have to do half of the stuff mentioned above. So here it is. I'm on Win7 64bit, 64bit Python3.4 and using a virtual environment. I'm using it to generate database schematics from django models using django-extensions, pretty useful!

  1. Download graphviz-2.38.msi from the graphviz Graphviz site
  2. Install the msi (I used cmd with Admin priviledges)

    msiexec /a graphviz-2.38.msi

  3. For some reason this doesn't add Graphviz to your system path, so you need to do that manually. For me this was

    SET PATH=%PATH%;C:\Program Files (x86)\Graphviz2.38\bin

  4. I then had to get a specific Windows pygraphviz wheel from this really useful site, specifically pygraphviz-1.3.1-cp34-none-win_amd64.whl

  5. Once I had this I then installed it using pip/mingw32 to my virtual environment

    $ pip install pygraphviz-1.3.1-cp34-none-win_amd64.whl

Now it's all working great.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!