admin管理员组文章数量:1406308
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.
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.
Share Improve this question edited Mar 5 at 23:36 AnilJ asked Mar 5 at 21:30 AnilJAnilJ 2,1313 gold badges38 silver badges62 bronze badges 9 | Show 4 more comments1 Answer
Reset to default 0For some reason, the python script did not pick the system path env variable. I solved this issue by explicitly setting the path where the 'dot' command is available.
import os
graphviz_path = "/usr/local/bin/"
os.environ["PATH"] = graphviz_path + os.pathsep + os.environ["PATH"]
print("path: ", os.environ["PATH"])
本文标签: pythonNot able to generate graphviz when runing on MacStack Overflow
版权声明:本文标题:python - Not able to generate graphviz when runing on Mac - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745006595a2637300.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
PosixPath('dot')
is basically equivalent to./dot
; it's not going to use your search path to find thedot
executable. – chepner Commented Mar 5 at 22:57PATH
. You may checkos.environ['PATH']
in your code, – furas Commented Mar 6 at 7:04