我需要使用 python AnyTree 包从字典中生成一棵树。所以我有一个类似下面结构的字典。
data = {'name': 'xyz',
'children': [{'name': 'node1',
'children': [{'name': 'node2'}]}]}
这个字典可以随着程序的执行而增长。我现在面临的问题是当我尝试将树导出为 png 时,DotExporter(root).to_picture("data.png")它会抛出一个文件未找到错误,如下所示
Traceback (most recent call last):File "C:/Users/.../data_modeling.py", line 88, in<module>creating_tree(main)
File "C:/Users/.../data_modeling.py", line 66, in creating_tree
DotExporter(root).to_picture("data.png")
File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\anytree\exporter\dotexporter.py", line 229, in to_picture
check_call(cmd)
File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 323, in check_call
retcode = call(*popenargs, **kwargs)
File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 304, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1155, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
我已经安装了 graphviz 包,并且我在带有 windows 的 python 3.7 上。但是使用DotExporter(root).to_dotfile('root.dot')我可以将树导出为点文件并使用在线转换器我可以将点文件转换为图像。但我需要从我的程序中将其导出为 png。
我已经用谷歌搜索了类似的问题,并在那里做了所有的建议和解决方案。任何帮助或建议都会很棒,任何其他树形图工具也可以。