Integration with viewersΒΆ
On platforms such as Windows, viewer programs opened by render()
with view=True
(or eqivalently 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()
>>> 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:
use a viewer that support live updates
use the Jupyter notebook or Qt Console (display the current version of the rendered graph in repeated add/render/view cycles)