安装Graphviz 2.38后出现“RuntimeError:请确保Graphviz可执行文件在您的系统路径上”的错误提示。

280

我下载了 Graphviz 2.38 MSI 版本并安装在文件夹 C:\Python34 下,然后运行了 pip install Graphviz,一切顺利。在系统路径中我添加了 C:\Python34\bin。当我尝试运行一个测试脚本时,在代码行 filename=dot.render(filename='test'),我收到了一条消息。

 RuntimeError: failed to execute ['dot', '-Tpdf', '-O', 'test'], make sure the Graphviz executables are on your systems' path

我试图将"C:\Python34\bin\dot.exe"添加到系统路径中,但没有成功,我甚至创建了一个名为"GRAPHVIZ_DOT"的新环境变量,并将其值设置为"C:\Python34\bin\dot.exe",但仍然无法正常工作。我尝试卸载Graphviz和pip uninstall graphviz,然后重新安装并再次使用pip安装,但仍然无效。

完整的回溯消息如下:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\graphviz\files.py", line 220, in render
    proc = subprocess.Popen(cmd, startupinfo=STARTUPINFO)
  File "C:\Python34\lib\subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "C:\Python34\lib\subprocess.py", line 1112, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Documents\Kissmetrics\curves and lines\eventNodes.py", line 56, in <module>
    filename=dot.render(filename='test')
  File "C:\Python34\lib\site-packages\graphviz\files.py", line 225, in render
    'are on your systems\' path' % cmd)
RuntimeError: failed to execute ['dot', '-Tpdf', '-O', 'test'], make sure the Graphviz executables are on your systems' path

有人对此有经验吗?

38个回答

0

Mac & Big Sur. Python 3.8.6 w/vs code. 虽然应该包含在图表软件包中,但我不得不手动安装Graphviz。

(mymltools) ➜  infrastructure git:(master) pip list
Package    Version
---------- -------
diagrams   0.18.0
graphviz   0.13.2
Jinja2     2.11.2
MarkupSafe 1.1.1
pip        20.3.2
setuptools 51.0.0
wheel      0.36.2

运行图表失败。然后手动运行了。

pipenv install graphviz

运行得非常好。


0

如果您没有使用Conda而是使用原始的Python,可以使用'brew install graphviz'命令进行安装。


0

MACOS - Monterey的解决方案

  1. 打开:终端
  2. 运行:pip install graphviz
  3. 运行:brew install graphviz
  4. 关闭:终端
  5. 打开:Anaconda(Jupyter或Spyder)
  6. 运行:import os
  7. os.environ["PATH"] += os.pathsep + "/usr/local/Cellar/graphviz/2.49.3/bin/dot"

(在修复此错误之前,您每次都需要运行此操作。) 棘手的部分是找到dot文件的位置。它是brew安装软件包的位置。(但应该类似于我给出的路径。) 通过运行以下命令进行测试:

import mglearn as mglearn
mglearn.plots.plot_animal_tree()

希望现在你已经准备好了!


0
你可以在Anaconda提示符中使用以下命令:
``` conda install python-graphviz ```
并确保在Anaconda提示符中安装pm4py:
``` pip install pm4py ```
最后,你需要尝试使用Anaconda提示符运行你的Python代码。

0
import os
os.environ["PATH"] += os.pathsep + "/Macintosh HD⁩/anaconda3⁩/lib⁩/⁨python3.7⁩/site-packages⁩/sphinx⁩/templates⁩/graphviz"

这对我解决了 MAC 上的 PATH 问题!


0
对于Mac用户(这对我有效):
# not required for graphviz but required for running the below command
pip3 install pipdeptree

pip3 install graphviz
brew install graphviz

# You could include in the .bashrc or .zshrc file to make it permanent. 
# As it may not save when you close the current terminal session!
export PATH="$PATH:/usr/local/Cellar/graphviz/8.1.0/bin";

然后我可以运行:
pipdeptree --graph-output png > dependencies.png

FYI,我在使用Python3.8的虚拟环境中进行了测试。

-1

对于 Windows 系统,以下两个命令在以管理员身份运行的 PowerShell 中适用:

  1. pip install graphviz

  2. choco install graphviz


请尽力根据提问者的系统定制您的答案。 - dsillman2000

-2

尝试在Python中执行以下操作: import sys !conda install --yes --prefix {sys.prefix} graphviz import graphviz


请在您的答案中添加更多细节,例如为什么这样做会修复问题。 - Deiv

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接