如何使用 graphviz 和 anytree 包在 Python 中渲染图形

Akh*_* PC 6 graphviz python-3.x anytree

我正在按照anytree 包的这个文档来渲染图形。请注意我已经在我的 mac 上安装了 graphviz 使用

pip3 install graphviz
Run Code Online (Sandbox Code Playgroud)

当我尝试执行此操作时

RenderTreeGraph(udo).to_picture("udo.png")
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

回溯(最近一次调用):文件“”,第 1 行,在 RenderTreeGraph(udo).to_picture("udo.png") 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ site-packages/anytree/dotexport.py”,第 51 行,在 to_picture check_call(cmd) 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py”,第 286 行,在check_call retcode = call(*popenargs, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 267, in call with Popen(*popenargs, * *kwargs) 作为 p:文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py”,第 707 行,在init 中 restore_signals, start_new_session) 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py”,第 1326 行,在 _execute_child 中 raise child_exception_type(errno_num, err_msg) FileNotFoundError: [Errno 2] 没有这样文件或目录:'点'

请帮我渲染树

Him*_*dri 6

我遇到了同样的错误。我还使用 pip3 来安装 graphviz。但是当我使用以下命令安装 graphviz 时,它解决了我的问题。

sudo apt install graphviz
Run Code Online (Sandbox Code Playgroud)