如何在Windows上从pygraphviz运行neato [英] How to run neato from pygraphviz on Windows

查看:334
本文介绍了如何在Windows上从pygraphviz运行neato的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在python(v 2.7)中使用pygraphviz和networkx创建网络映射.我发现了一个在stackoverflow上看起来非常有用的脚本:

I am trying to use pygraphviz and networkx in python (v 2.7) to create a network map. I found a script that looks very useful on stackoverflow:

import networkx as nx
import numpy as np
import string
import pygraphviz

dt = [('len', float)]
A = np.array([(0, 0.3, 0.4, 0.7),
               (0.3, 0, 0.9, 0.2),
               (0.4, 0.9, 0, 0.1),
               (0.7, 0.2, 0.1, 0)
               ])*10
A = A.view(dt)

G = nx.from_numpy_matrix(A)
G = nx.relabel_nodes(G, dict(zip(range(len(G.nodes())),string.ascii_uppercase)))    

G = nx.to_agraph(G)

G.node_attr.update(color="red", style="filled")
G.edge_attr.update(color="blue", width="2.0")

G.draw('/tmp/out.png', format='png', prog='neato')

我在最后一行出现错误,基本上找不到neato:

I get an error on the last line, basically it cannot find neato:

"ValueError:在路径中找不到程序neato."

"ValueError: Program neato not found in path."

该错误涉及pygraphviz的agraph.py文件,但是当我查看agraph.py

The error refers to the agraph.py file for pygraphviz, but I cannot see anything that could be causing the problem when I look through agraph.py

任何想法如何解决这个问题?我正在使用Windows和IDLE进行编码. 谢谢!

Any ideas how to resolve this? I am using windows and IDLE for my coding. Thanks!

推荐答案

我遇到了同样的问题.如果其他人都在努力使pygraphvis在Windows上正常工作,这就是我要做的事情.

I had the same problem. Here's what I did in case anyone else is struggling to get pygraphvis working on Windows.

首先,我安装了graphviz.我试图安装pygraphvis thrugh pip,但是它拒绝工作.最终,我找到了非官方的Windows二进制文件,所以我安装了它.现在可以导入模块了,但是调用G.layout()会导致上述错误.

First off, I installed graphviz. I tried to install pygraphvis thrugh pip, but it refused to work. Eventually, I found the unofficial Windows binaries, so I installed that. Importing the module now works, but calling G.layout() led to the above error.

调用neato -V起作用了,所以在我的PATH上.我发现问题是python在安装pygraphvis之前创建的命令提示符中运行,因此PATH并未更新.重新启动命令提示符可解决此问题,但导致出现新错误,有关C:\Program无效命令的问题.

Calling neato -V worked, so it was on my PATH. I figured out that the problem was that python was running in a command prompt that was created prior to installing pygraphvis, so PATH wasn't updated. Restarting the command prompt fixed this, but led to a new error, something about C:\Program not being a valid command.

我发现pygraphvis可能无法正确引用该路径,这意味着它会在Program Files中的空格处切断.我通过将其符号链接到没有空格的路径来解决了这个问题.

I figured that pygraphvis was probably failing to quote the path correctly, meaning it cuts off at the space in Program Files. I solved the problem by symlinking it to a path without spaces.

mklink /d C:\ProgramFilesx86 "C:\Program Files (x86)"

请注意,这必须在管理员模式下运行.您可以通过以下方法进行操作:转到开始菜单,输入cmd,然后按Ctrl + Shift + Enter.

Note that this must be run in admin mode. You can do it by going to the start menu, typing in cmd, and then hitting Ctrl+shift+enter.

此后,我编辑了PATH以引用符号链接,重新启动了cmd,一切正常.

After this, I edited my PATH to refer to the symlink, restarted cmd, and everything worked.

这篇关于如何在Windows上从pygraphviz运行neato的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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