Package | 解决 graphviz.backend.execute.ExecutableNotFound: failed to execute PosixPath(‘dot‘)

.

背景

实验环境是Ubuntu中使用docker container。
试图在container里使用torchviz可视化DL模型的计算图,其中,torchviz已基于以下指令安装。

pip install torchviz

调用torchviz.make_dot可视化,出现报错,具体报错信息如下:

Traceback (most recent call last): File “/opt/conda/lib/python3.8/site-packages/graphviz/backend/execute.py”, line 81, in run_check
proc = subprocess.run(cmd, **kwargs) File “/opt/conda/lib/python3.8/subprocess.py”, line 493, in run
with Popen(*popenargs, **kwargs) as process: File “/opt/conda/lib/python3.8/subprocess.py”, line 858, in init
self._execute_child(args, executable, preexec_fn, close_fds, File “/opt/conda/lib/python3.8/subprocess.py”, line 1704, in
_execute_child
raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: PosixPath(‘dot’)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File “test.py”, line 715, in
vis_graph() File “test.py”, line 705, in vis_graph
torchviz.make_dot( File “/opt/conda/lib/python3.8/site-packages/graphviz/_tools.py”, line 171, in wrapper
return func(*args, **kwargs) File “/opt/conda/lib/python3.8/site-packages/graphviz/rendering.py”, line 122, in render
rendered = self._render(*args, **kwargs) File “/opt/conda/lib/python3.8/site-packages/graphviz/_tools.py”, line 171, in wrapper
return func(*args, **kwargs) File “/opt/conda/lib/python3.8/site-packages/graphviz/backend/rendering.py”, line 324, in render
execute.run_check(cmd, File “/opt/conda/lib/python3.8/site-packages/graphviz/backend/execute.py”, line 84, in run_check
raise ExecutableNotFound(cmd) from e graphviz.backend.execute.ExecutableNotFound: failed to execute PosixPath(‘dot’), make sure the Graphviz executables are on your systems’ PATH

.

解决方案

报错信息中提示:“make sure the Graphviz executables are on your systems’ PATH”,然后搜索引擎查了一下发现类似的问题。

需要在环境中安装graphviz工具包,指令如下:

apt-get install graphviz -y

如果报错找不到graphviz,更新一下apt的源再安装一次:

apt-get update
apt-get install graphviz -y

然后就安装成功啦,可以正常使用可视化功能啦!

欢迎评论区讨论,预祝大家计算图顺顺顺!

ps 兔年第一篇,大家新年快乐呀!^ _________________________________________________ ^

.

你可能感兴趣的:(Package,深度学习,torchviz,graphviz,pytorch,python)