Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to execute shell command in python program (I have ubuntu). More specifically I want to create graph using graphviz in python script. My code is

os.system("dot -Tpng -o graph.png")

It does not work, but if I just type dot -Tpng -o graph.png in command line then everything is fine. Do you know what the problem? Thank you!

Edit: Does not work means that nothing happens, there are no errors.

Output from dot -v -Tpng -o graph.png:

dot - graphviz version 2.26.3 (20100126.1600)
Activated plugin library:
Using textlayout: textlayout:cairo
Activated plugin library:
Using layout: dot:dot_layout
Using render: cairo:cairo
Using device: png:cairo:cairo
The plugin configuration file:
        was successfully loaded.
    render  :  cairo dot fig gd map ps svg tk vml vrml xdot
    layout  :  circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
    textlayout  :  textlayout
    device  :  canon cmap cmapx cmapx_np dot eps fig gd gd2 gif gv imap         imap_np ismap jpe jpeg jpg pdf plain plain-ext png ps ps2 svg svgz tk vml vmlz vrml wbmp x11 xdot xlib
    loadimage   :  (lib) eps gd gd2 gif jpe jpeg jpg png ps svg
share|improve this question
For future coding related questions, post to Stack Overflow. +1 for Python :-) – invert Mar 3 '12 at 18:23
up vote 1 down vote accepted

I figured out the problem. I should close file before executing the command.

share|improve this answer

Strange, I just tried with the same command and it gave me the expected output (that doesn't exist) Are you sure you have

import os

? Also, are you sure that this piece of code that executes the 'dot' command isn't in a untrue condition (in an 'if' statement that is untrue, so the piece of code after this never executes)?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.