1

Running the following code (example from https://pypi.org/project/graphviz/):

from graphviz import Digraph
dot = Digraph(comment='The Round Table', format='jpeg')
dot.node('A', 'King Arthur')
dot.node('B', 'Sir Bedevere the Wise')
dot.node('L', 'Sir Lancelot the Brave')
dot.edges(['AB', 'AL'])
dot.edge('B', 'L', constraint='false')
dot.render('test-output/round-table.gv', view=True) 

Results in:

Format: "jpeg" not recognized. Use one of:

It seems like graphviz cannot write a file to any format. How to solve this?

Inge
  • 135
  • 1
  • 6
  • Off-topic, but: it's a really bad idea to store images of graphs as JPEGs. Consider using a vector format, or, if you want to rasterize, a lossless format like PNG. – gspr Aug 10 '20 at 09:21
  • Looks like jpeg is not enabled in your version of dot. What does the command `dot -v` give, when issued in a command window? (also give a `C` to leave the dot program again). – albert Aug 10 '20 at 10:12

1 Answers1

1

My method: (I'm win10, other op may skip to step 2)

  1. Add "bin/" of Graphviz into environment path.

    • My Graphviz installation path: D:\software\graphviz\Graphviz2.44.1\. It has 4 folders: "bin","include","lib","share"
    • So I add D:\software\graphviz\Graphviz2.44.1\bin to my environment path
  2. cmd run command "dot -c" to config.

    • dot means D:\software\graphviz\Graphviz2.44.1\bin\dot.exe. Due to step 1, I just need to run dot -c, otherwise, I need to run D:\software\graphviz\Graphviz2.44.1\bin\dot.exe -c
    • dot -c means: Configure plugins (Writes $prefix/lib/graphviz/config with available plugin information. Needs write privilege.)
  3. Add path to your code:

# add
import os 
path_graphviz = "D:/software/graphviz/Graphviz2.44.1/bin" # replace by your Graphviz bin path
os.environ["PATH"] += os.pathsep + path_graphviz

# origin code
from graphviz import Digraph
dot = Digraph(comment='The Round Table', format='jpeg')
dot.node('A', 'King Arthur')
dot.node('B', 'Sir Bedevere the Wise')
dot.node('L', 'Sir Lancelot the Brave')
dot.edges(['AB', 'AL'])
dot.edge('B', 'L', constraint='false')
dot.render('test-output/round-table.gv', view=True)
  1. I success on my computer. here is result
ciwenjia
  • 21
  • 2
  • Running `dot -c` as Administrator fixed the Format not recognized error. I also had to copy dot.exe to neato.exe to be able to use neato. Thanks! – ded' Aug 25 '20 at 18:17