[Python] Not able to generate graphviz when runing on Mac

Discussão em 'Python' iniciado por Stack, Março 5, 2025.

  1. Stack

    Stack Membro Participativo

    I have followed the recommended steps:

    • Installed graphviz on mac using brew install graphviz. Please see below.

    ls /usr/local/Cellar/graphviz/12.2.1/bin/
    acyclic diffimg dot_sandbox graphml2gv gvmap gxl2gv patchwork twopi
    bcomps dijkstra edgepaint gv2gml gvmap.sh mm2gv prune unflatten
    ccomps dot fdp gv2gxl gvpack neato sccmap
    circo dot2gxl gc gvcolor gvpr nop sfdp
    cluster dot_builtins gml2gv gvgen gxl2dot osage tred

    • Installed the python package using pip3 install graphviz. Please see below.

    ls /Users/foo/Library/Python/3.7/lib/python/site-packages/graphviz/
    __init__.py _tools.py dot.py jupyter_integration.py rendering.py
    __pycache__ backend encoding.py parameters saving.py
    _compat.py base.py exceptions.py piping.py sources.py
    _defaults.py copying.py graphs.py quoting.py unflattening.py

    • The PATH variable is also set correctly.

    echo $PATH
    /usr/local/Cellar/graphviz/12.2.1/bin:/usr/local/opt/curl/bin:/usr/local/opt/curl/bin:


    However, when I run the python code to generate a basic graph:

    import json
    import graphviz

    if __name__ == '__main__':
    json_string = '{"192.168.133.166":[{}],"192.168.133.180":[{}],"192.168.133.64":[{}]} '

    g1 = graphviz.Digraph(name="my_graph")
    data = json.loads(json_string)

    if isinstance(data, dict):
    for k, v in data.items():
    g1.node(k, None)
    print(k, v)

    # Render the graph
    g1.render(filename="my_graph")


    It fails with the following error.

    graphviz.backend.execute.ExecutableNotFound: failed to execute PosixPath('dot'), make sure the Graphviz executables are on your systems' PATH


    When I run the dot command from command line, it works fine. /usr/local/Cellar/graphviz/12.2.1/bin/dot -T jpeg -O sample.dot

    Not sure what is still missing.

    Continue reading...

Compartilhe esta Página