Subgraph Python setup

Hi Graphviz,
I am working to setup the digraph and subgraph example found here

I have pip installed graphviz and am trying to get this code to run locally in a python script. I am getting an invalid syntax error on the digraph name ‘G’. Are there any additional installs or requirements that are not specified in this example that I sent in the link?

(Note: I am not a Python user or a pip user. The following is based on lots of Stackoverflow comments)
I don’t believe that pip really installs Graphviz. I believe pip only installs an interface to Graphviz. To check, go to a command line/terminal and type dot -V.
To install Graphviz, go here: Download | Graphviz

Thank you for the reply! I actually have tried ‘brew install Graphviz’ and I am also getting a similar error in how digraph initialization is not getting recognized by my python file. I am using Pycharm as an editor. I looking at the Python interpreter, I see that the Graphviz package version 0.19.1 is installed. I get an invalid syntax error on the digraph declaratoion. Is this version not correct?

That is not a Graphviz version. Graphviz versions run from (approximately) 2.43 to (approximately) 3.0. I believe you are seeing the version number of the Python-to-Graphviz interface.
Read this graphviz · PyPI and note the text that says:

To render the generated DOT source code, you also need to install Graphviz (download page, archived versions, installation procedure for Windows).

I wish they would rename their interface and/or improve their documentation.

Thank you for the reply! I actually have tried ‘brew install Graphviz’ and I am also getting a similar error in how digraph initialization is not getting recognized by my python file.

dot -v on the terminal returns:
dot - graphviz version 2.50.0 (20211204.2007)

Also, in my Pycharm editor interpreter window I see graphviz with a version of 0.19.1

Are there any other dependencies that I am not considering?

Best guess: you probably have everything you need installed. Maybe there really is (just) a syntax error. If so, is it a Python syntax error or a Graphviz syntax error?

On this page (graphviz · PyPI) note the part that says

check the generated source code

I’d do that and then run that “manually” thru dot

1 Like

thank you! I am able to get the diagram to generate by running the script as a dot file and running the scripts using dot