Python-MacOSX中graphviz模块遇到的问题
当我尝试使用Python-MacOSX中graphviz模块遇到的问题,python,python-3.x,graphviz,Python,Python 3.x,Graphviz,当我尝试使用graphviz模块查看a.dot文件时,出现以下错误: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/graphviz/backend.py", line 158, in run proc = subprocess.Popen(cmd, startupinfo=get_startu
graphviz
模块查看a.dot
文件时,出现以下错误:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/graphviz/backend.py", line 158, in run
proc = subprocess.Popen(cmd, startupinfo=get_startupinfo(), **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in `__init__`
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dot': 'dot'
在处理上述异常期间,发生了另一个异常:
Traceback (most recent call last):
File "/Users/user_name/Desktop/New code folder September 7 2019/Introduction to machine learning/ch2_0002.py", line 118, in <module>
test_cancer_pre_pruning()
File "/Users/user_name/Desktop/New code folder September 7 2019/Introduction to machine learning/ch2_0002.py", line 109, in test_cancer_pre_pruning
graphviz.Source(dot_graph).view()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/graphviz/files.py", line 242, in view
quiet=quiet, quiet_view=quiet_view)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/graphviz/files.py", line 209, in render
quiet=quiet)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/graphviz/backend.py", line 205, in render
run(cmd, capture_output=True, cwd=cwd, check=True, quiet=quiet)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/graphviz/backend.py", line 161, in run
raise ExecutableNotFound(cmd)
graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'Source.gv'], make sure the Graphviz executables are on your systems' PATH
回溯(最近一次呼叫最后一次):
文件“/Users/user_name/Desktop/New code folder 2019年9月7日/Introduction to machine learning/ch2_0002.py”,第118行,在
test_cancer_pre_修剪()
文件“/Users/user\u name/Desktop/New code folder 2019年9月7日/Introduction to machine learning/ch2\u 0002.py”,第109行,测试前剪枝
graphviz.Source(dot_graph.view)()
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/graphviz/files.py”,第242行,在视图中
安静=安静,安静\u视图=安静\u视图)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/graphviz/files.py”,第209行,在渲染中
安静=安静)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/graphviz/backend.py”,第205行,在render中
运行(cmd,capture_output=True,cwd=cwd,check=True,quiet=quiet)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/graphviz/backend.py”,第161行,正在运行
raise ExecutableNotFound(cmd)
graphviz.backend.ExecutableNotFound:未能执行['dot'、'-Tpdf'、'-O'、'Source.gv'],请确保graphviz可执行文件位于系统的路径上
我试过:
- pip3安装graphviz
- 康达安装graphviz
两者似乎都没有解决问题。可能dot
不在您的路径中。如何解决此问题?请检查您的路径变量。检查是否可以从命令行(dot-V
)启动dot,以防无法将其添加到path变量中。