Integration with viewersΒΆ

On platforms such as Windows, viewer programs opened by render() with view=True (or equivalently with the view() shortcut-method) might lock the (PDF, PNG, etc.) file for as long as the viewer is open (blocking re-rendering it with a Permission denied error).

Tip

You can use the tempfile.mktemp() function from the stdlib tempfile module to render to a different file for each invocation. This avoids needing to close the viewer window each time within such an incremental workflow (and also serves to preserves the intermediate steps).

>>> import tempfile
>>> import graphviz

>>> g = graphviz.Graph()

>>> g.node('spam')
>>> doctest_mark_exe()  # skip this line

>>> g.view(tempfile.mktemp('.gv'))
'C:\\Users\\User\\AppData\\Local\\Temp\\tmp3aoie8d0.gv.pdf'

>>> g.view(tempfile.mktemp('.gv'))
'C:\\Users\\User\\AppData\\Local\\Temp\\tmphh4ig7a_.gv.pdf'

Other options: