Python:pygraphviz和graphviz的安装问题 [英] Python: Installation issues with pygraphviz and graphviz

查看:643
本文介绍了Python:pygraphviz和graphviz的安装问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到许多关于在Windows上为Python 2.7正确安装pygraphvizgraphviz的困难的问题.但是我发现没有答案可以解决我的问题.这是我所做的:

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:

  • 我首先使用非官方的Windows二进制文件安装了pygraphviz 在我的anaconda(python)文件夹中,使用链接 C:\Users\chamar\AppData\Local\Continuum\Anaconda)
  • 下载了graphviz-2.36.msi并将其安装为默认设置 路径C:\Program Files (x86)\Graphviz2.36
  • 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

Python中的命令import pygraphviz有效.但是当我想使用此功能nx.graphviz_layout时,我会得到raise ValueError("Program %s not found in path."%prog)

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)

可能导致此问题的原因是pygraphviz无法找到graphviz的路径.现在,由于我使用非官方的Windows二进制文件安装了pygraphviz,我可以修改哪个文件以链接libraryinclude来链接graphviz的路径?当您不使用非官方二进制文件时,通常会在pygraphvizsetup.py路径中找到libraryinclude路径.

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.

更新1

我在SOFTWARE下的Regedit中的PATH中添加了一个带有新key(默认值)为C:\Program Files (x86)\Graphviz2.36\bin

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

更新2

我在pydot.py文件中遇到一个错误,原因是Python难以定位Graphviz的路径.我进行了如下更改:

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)

我得到:

    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.

为什么?

推荐答案

以下是我为pygraphviz在Python 3.4上工作而执行的步骤(我认为,如果您遵循类似的步骤,则它应在Python 2.x上工作).我只是在这里记录它,以供将来的页面访问者:

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 :

先决条件:

  1. wheel (默认情况下应在较新的发行版中出现)
  2. pygraphviz的正确Windows版本(非官方版本).在Win7 x64上,我选择了"pygraphviz- $ version -cp34-none-win_amd64.whl". (请注意cp34指示python版本.)
  3. Graphviz 安装程序版本2.38(为此构建了上述工具) )
  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)

步骤:

  1. 运行Graphviz安装程序
  2. 将Graphviz \ bin文件夹添加到您的用户或系统PATH
  3. 检查:打开命令提示符并执行twopi -V.您应该能够看到控制台上打印的Graphviz版本.
  4. 现在转到您的Python环境(例如,运行anaconda.bat,这是您可以运行python的提示)
  5. 运行pip install pygraphviz‑*$version*-cp34‑none‑win_amd64.whl
  6. 您已完成:)!运行示例脚本查看一切是否顺利.
  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.

这篇关于Python:pygraphviz和graphviz的安装问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆