在 Windows 上安装 pygraphviz

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4571067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:53:24  来源:igfitidea点击:

Installing pygraphviz on windows

windowsfailed-installationpygraphviz

提问by Jonathan

After installing the latest graphviz (2.26.3) on my Windows 7 Ultimate 64bit, I receive the following error:

在我的 Windows 7 Ultimate 64bit 上安装最新的 graphviz (2.26.3) 后,我收到以下错误:

C:>easy_install pygraphviz Searching for pygraphviz Reading http://pypi.python.org/simple/pygraphviz/Reading http://networkx.lanl.gov/pygraphvizReading http://networkx.lanl.gov/wiki/downloadReading http://networkx.lanl.gov/download/pygraphvizReading http://sourceforge.net/project/showfiles.php?group_id=122233&package_id=161979Reading http://networkx.lanl.gov/downloadBest match: pygraphviz 1.1.dev1947 Downloading http://networkx.lanl.gov/download/pygraphviz/pygraphviz-1.1.dev1947.tar.gzProcessing pygraphviz-1.1.dev1947.tar.gz Running pygraphviz-1.1.dev1947\setup.py -q bdist_egg --dist-dir c:\users\jonathan\appdata\local\temp\easy_install-apywwk\pygraphviz-1.1.dev1947\egg-dist-tmp-nvd0pa Trying pkg-config Failed to find pkg-config Trying dotneato-config Failed to find dotneato-config

Your graphviz installation could not be found.

Either the graphviz package is missing on incomplete (binary packages graphviz-dev or graphviz-devel missing?).

If you think your installation is correct you will need to manually change the include_path and library_path variables in setup.py to point to the correct locations of your graphviz installation.

The current setting of library_path and include_path is: library_path=None include_path=None

error: None

C:>easy_install pygraphviz 搜索 pygraphviz 阅读 http://pypi.python.org/simple/pygraphviz/阅读 http://networkx.lanl.gov/pygraphviz阅读 http://networkx.lanl.gov/wiki/download阅读 http://networkx.lanl.gov/download/pygraphviz阅读 http://sourceforge.net/project/showfiles.php?group_id=122233&package_id=161979阅读 http://networkx.lanl.gov/download最佳匹配:pygraphviz 1.1 .dev1947 下载 http://networkx.lanl.gov/download/pygraphviz/pygraphviz-1.1.dev1947.tar.gz处理 pygraphviz-1.1.dev1947.tar.gz 运行 pygraphviz-1.1.dev1947\setup.py -q bdist_egg --dist-dir c:\users\jonathan\appdata\local\temp\easy_install-apywwk\pygraphviz-1.1.dev1947 \egg-dist-tmp-nvd0pa 尝试 pkg-config 未能找到 pkg-config 尝试 dotneato-config 未能找到 dotneato-config

找不到您的 graphviz 安装。

在不完整的情况下缺少 graphviz 包(缺少二进制包 graphviz-dev 或 graphviz-devel?)。

如果您认为您的安装是正确的,您将需要手动更改 setup.py 中的 include_path 和 library_path 变量以指向您的 graphviz 安装的正确位置。

library_path 和 include_path 当前设置为: library_path=None include_path=None

错误:无

Any thoughts how to fix this?
This seems to be a different problem than the one described here.
Has anyone had success in installing pygraphviz on Windows? How?

任何想法如何解决这个问题?
这似乎是一个与此处描述的问题不同的问题。
有没有人在 Windows 上安装 pygraphviz 成功?如何?

回答by Andrew Filev

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

这对我有用。前提条件:安装 mingw32(如果您正在使用它,则包含在 pythonxy distrib 中),Graphviz

1) Download pygraphviz sources

1)下载pygraphviz源

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

2) 编辑 setup.py 以将路径更改为 smth 之类的

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.

请注意,它是 \bin,而不是 \lib。与库链接对我不起作用。

3) run python setup.py build -c mingw32

3)运行 python setup.py build -c mingw32

Result of step 3:

第 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

4) 将刚刚构建的 lib.win32-2.7(名为 的单个子文件夹)的结果复制pygraphviz到 Python 的 site-packages 文件夹中

Enjoy!

享受!

回答by Gabriel

for windows 64-bit:

对于 Windows 64 位:

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"

类似于 Andrew Filev 所写的内容,但您需要使用 pythonxy,并且您需要将 Graphviz 安装在不包含空格的文件夹中(包括程序的根文件夹:“Graphviz 2.28”=>“Graphviz2.28”

so:

所以:

1) uninstall python 2.7

1)卸载python 2.7

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

2) 安装 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"

3)安装Graphviz 2.28(我测试的唯一一个)确保安装路径中没有空格。一个很好的例子是:“C:\Graphviz2.28”

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

4)将pygraphviz下载为zip(源)并解压​​缩。

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

5)修改顶部附近的setup.py以具有

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

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

6)运行: python setup.py build -c mingw32

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

7) 看到这个结果后(比之前发布的要好得多):

>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

将刚刚构建的 lib.win32-2.7(名为 的单个子文件夹pygraphviz)的结果复制到您的 Python 的 site-packages 文件夹中,您可能必须自己制作该文件夹 + 将 pygraphviz 的新根文件夹绑定到环境变量PYTHONPATH

For example the final library could be situated here:

例如,最终的库可以位于这里:

C:\Python27\libs\site_packages\pygraphviz

回答by Tom

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_pathand include_pathare no longer the names of the relevant variables. Here's what worked for me on Windows 7, 32-bit Python 2.7:

我只是花了半个小时试图弄清楚为什么上面的答案对我不起作用,结果它们已经过时library_path并且include_path不再是相关变量的名称。以下是在 Windows 7、32 位 Python 2.7 上对我有用的内容:

setup.py

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

然后运行 python setup.py build -c mingw32

回答by DrBuck

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!

一个老问题,但我刚刚完成了这个并且找不到 Python 3 的具体答案,我不必做上面提到的一半的事情。所以在这里。我使用的是 Win7 64 位、64 位 Python3.4 并使用虚拟环境。我正在使用它使用django-extensions从 django 模型生成数据库原理图,非常有用!

  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

  1. 从graphviz Graphviz 站点下载graphviz-2.38.msi
  2. 安装 msi(我使用 cmd 和管理员权限)

    msiexec /a graphviz-2.38.msi

  3. 出于某种原因,这不会将 Graphviz 添加到您的系统路径中,因此您需要手动执行此操作。对我来说这是

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

  4. 然后我必须从这个非常有用的站点获得一个特定的 Windows pygraphviz 轮,特别是 pygraphviz-1.3.1-cp34-none-win_amd64.whl

  5. 一旦我有了这个,我就使用 pip/mingw32 将它安装到我的虚拟环境中

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

Now it's all working great.

现在一切都很好。

回答by 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.

PyGraphviz 使用 C 语言扩展模块(由 SWIG 生成)。所以你需要一个编译器来构建扩展。您可能需要与构建 Python 可执行文件相同的编译器。

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

这个问题中有一些信息为 Windows 构建 Python C 扩展模块

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

以及http://www.swig.org/Doc1.3/Python.html#Python_nn12