graphviz安装仍报错 | 路径问题 | 已解决

问题:

【Python】安装Pygraphviz的正确姿势-CSDN博客

2 pygraphviz在windows10 64位下的安装问题(反斜杠的血案)

安装PyGraphviz的两个坑 – 数学思绪 (jhanmath.com)

python - Pip install pygraphviz 失败:pygraphviz 的构建轮失败 - SegmentFault 思否

报错:

FileNotFoundError                         Traceback (most recent call last)
D:\Anacondasetup\lib\site-packages\graphviz\backend\execute.py in run_check(cmd, input_lines, encoding, quiet, **kwargs)
     77         else:
---> 78             proc = subprocess.run(cmd, **kwargs)
     79     except OSError as e:

D:\Anacondasetup\lib\subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    492 
--> 493     with Popen(*popenargs, **kwargs) as process:
    494         try:

D:\Anacondasetup\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    857 
--> 858             self._execute_child(args, executable, preexec_fn, close_fds,
    859                                 pass_fds, cwd, env,

D:\Anacondasetup\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1310             try:
-> 1311                 hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   1312                                          # no special security

FileNotFoundError: [WinError 2] 系统找不到指定的文件。

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

ExecutableNotFound                        Traceback (most recent call last)
<ipython-input-1-d3a92eb95c6d> in <module>
      4 dot.node('B', 'Node B')
      5 dot.edge('A', 'B')
----> 6 dot.render('test-output', view=True)

D:\Anacondasetup\lib\site-packages\graphviz\_tools.py in wrapper(*args, **kwargs)
    169                               category=category)
    170 
--> 171             return func(*args, **kwargs)
    172 
    173         return wrapper

D:\Anacondasetup\lib\site-packages\graphviz\rendering.py in render(self, filename, directory, view, cleanup, format, renderer, formatter, neato_no_op, quiet, quiet_view, outfile, engine, raise_if_result_exists, overwrite_source)
    120         args.append(filepath)
    121 
--> 122         rendered = self._render(*args, **kwargs)
    123 
    124         if cleanup:

D:\Anacondasetup\lib\site-packages\graphviz\_tools.py in wrapper(*args, **kwargs)
    169                               category=category)
    170 
--> 171             return func(*args, **kwargs)
    172 
    173         return wrapper

D:\Anacondasetup\lib\site-packages\graphviz\backend\rendering.py in render(engine, format, filepath, renderer, formatter, neato_no_op, quiet, outfile, raise_if_result_exists, overwrite_filepath)
    324     assert filepath is not None, 'work around pytype false alarm'
    325 
--> 326     execute.run_check(cmd,
    327                       cwd=filepath.parent if filepath.parent.parts else None,
    328                       quiet=quiet,

D:\Anacondasetup\lib\site-packages\graphviz\backend\execute.py in run_check(cmd, input_lines, encoding, quiet, **kwargs)
     79     except OSError as e:
     80         if e.errno == errno.ENOENT:
---> 81             raise ExecutableNotFound(cmd) from e
     82         raise
     83 

ExecutableNotFound: failed to execute WindowsPath('dot'), make sure the Graphviz executables are on your systems' PATH

解决:

从报错信息来看,问题在于系统无法找到 Graphviz 的可执行文件(dot)。这通常意味着 Graphviz 要么没有安装要么没有正确地添加到系统的 PATH 环境变量中

尝试pip install graphviz、pip install python-graphviz、pip install pygraphviz和去env里查看都已经安装了,但是运行命令的时候仍然会报错,无法绘制。所以应该是路径问题。        找了几个帖子,都是Anaconda下的Graphviz文件,bin添加到路径。但是在我的环境里找不到。于是下载Graphviz再setup后添加路径,解决√ 参考链接

让我们一步步解决这个问题:

  1. 确保 Graphviz 已安装:
  2. 将 Graphviz 添加到系统 PATH:
    • 右击 "此电脑" 或 "我的电脑",选择 "属性"
    • 点击 "高级系统设置"
    • 点击 "环境变量"
    • 在 "系统变量" 中找到 "Path",选中它并点击 "编辑"
    • 点击 "新建",添加 Graphviz 的 bin 目录路径(C:\Program Files (x86)\Graphviz2.38\bin)
    • 点击 "确定" 保存所有更改
  3. 重启您的 Jupyter Notebook 或 IDE:
    • 环境变量更改后,需要重启应用程序才能生效
  4. 验证安装:
    • 打开命令提示符(CMD)
    • 输入 dot -v,如果正确安装,应该会显示 Graphviz 的版本信息

然后就有我想绘制的决策树了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值