我如何运行“点"作为Python的命令? [英] How do I run "dot" as a command from Python?

查看:94
本文介绍了我如何运行“点"作为Python的命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac OSX Leopard上使用Python.

I am using Python on Mac OSX Leopard.

我正在尝试从Python运行程序点"(Graphviz的一部分):

I am trying to run the program 'dot' (part of Graphviz) from Python:

# -*- coding: utf-8 -*-
import os

print os.environ['PATH']
print os.system("ls >> a.txt")
print os.system("dot -o9.png -Tpng ./6.dot")

命令"ls"仅用于确保python在正确的目录中.它是.我得到的结果是:

The command "ls" is there just to make sure that python is in the correct directory. It is. The result that I get is:

/usr/bin:/bin:/usr/sbin:/sbin 0 32512

/usr/bin:/bin:/usr/sbin:/sbin 0 32512

我的理解是32512错误意味着python无法找到该文件,并且由于存在文件6.dot(如果我从终端运行"dot -o9.png -Tpng ./6.dot",没有错误,并且生成了9.png文件),我认为Python找不到该点文件.

My understanding is that 32512 error means that python could not find the file, and since the file 6.dot is there (If I run "dot -o9.png -Tpng ./6.dot" from the terminal I receive no error, and 9.png gets produced), I assume Python can't find the dot file.

我可能需要将点文件添加到路径中.但是我不知道在哪里.如果我运行:

I probably need to add the dot file to the path. But I don't know where is it. If I run:

whereis dot

我没有收到答案.

如何找到点可执行文件?
另外,我可以从Python内部将点程序作为命令运行吗?

How can I find the dot executable?
Alternatively, can I run the dot program as a command from inside Python?

推荐答案

您应该更改PATH行,使其包含包含dot的目录.该目录是/usr/local/bin,没有/dot.

You should change the PATH line so it includes the directory which contains dot. That directory is /usr/local/bin, without /dot.

这篇关于我如何运行“点"作为Python的命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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