[英]How do I make sure the Graphviz executables are on my system's PATH?
I am working with Graphviz using Python 3 on Sublime Text 3. When I run this code:我在 Sublime Text 3 上使用 Python 3 使用 Graphviz。当我运行此代码时:
data = tree.export_graphviz(dtGini[55], out_file = None)
graph = graphviz.Source(data)
graph.render("testingthis")
I get these errors:我收到这些错误:
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'testingthis'], make sure the Graphviz executables are on your systems' PATH
It looks like it can't find the files it needs.看起来它找不到它需要的文件。 In Sublime Text 3, my user settings for Conda are:
在 Sublime Text 3 中,我对 Conda 的用户设置是:
{
// executable is the path to anaconda's python
// this python executable is used in order to find conda
"executable": "C:/ProgramData/Miniconda3/python.exe",
// Directory in which the conda envs are stored
// Default location is the user's home directory
"environment_directory": "C:/ProgramData/Miniconda3/envs",
// configuration is the path to conda's configuration file
"configuration": "~/.condarc"
}
I have these environment variables from my control panel:我的控制面板中有这些环境变量:
C:\ProgramData\Miniconda3\Scripts\
C:\ProgramData\Miniconda3\
C:\ProgramData\Miniconda3\conda-meta\history
C:\Users\X\AppData\Local\conda\conda\pkgs
C:\Users\X\AppData\Local\conda\conda\pkgs\graphviz-2.38-hfd603c8_2\Library\bin
C:\Users\X\AppData\Local\conda\conda\pkgs\graphviz-2.38-hfd603c8_2\Library\bin\dot.exe
In the Anaconda prompt, when I enter Python, hit enter, and then type in "import graphviz" I get no error.在 Anaconda 提示符下,当我输入 Python 时,按 Enter,然后输入“import graphviz”,我没有收到任何错误。 In Sublime Text 3, if I just have a file like graph.py
在 Sublime Text 3 中,如果我只有一个像 graph.py 这样的文件
import graphviz
It executes without any errors.它执行时没有任何错误。
Any ideas on how I can solve this?关于如何解决这个问题的任何想法? It's driving me nuts.
它让我发疯。 Thank you!
谢谢!
I followed a solution posted by @aprameyo roy here > "RuntimeError: Make sure the Graphviz executables are on your system's path" after installing Graphviz 2.38 安装Graphviz 2.38后,我遵循了@aprameyo roy在此处发布的解决方案> “ RuntimeError:确保Graphviz可执行文件在系统的路径上”
The system path needed took some finding on my PC - I had used Ananconda to install the graphviz package. 我的PC上找到了所需的系统路径-我曾使用Ananconda安装graphviz软件包。
Adding these two commands to my jupyter notebook solved the issue - change the C:/ address to your install location: 将这两个命令添加到我的jupyter笔记本即可解决此问题-将C:/地址更改为您的安装位置:
(PS. I think you will need to re-run this after every kernal restart.) (PS。我认为您需要在每次内核重新启动后重新运行。)
# extra step to allow graphviz to be found
import os
os.environ["PATH"] += os.pathsep + 'C:/Users/jed/Anaconda3/envs/keras/Library/bin/graphviz/'
对我来说,解决方案是从他们的网站下载Graphviz(即使我已经从CMD下载了它),然后更改PATH变量以反映安装位置。
In case window i resolved this problem by following below steps:如果窗口我通过以下步骤解决了这个问题:
step 1. install stable_windows_10_cmake_Release_Win32_graphviz-install-2.49.3-win32.exe步骤 1. 安装 stable_windows_10_cmake_Release_Win32_graphviz-install-2.49.3-win32.exe
step2.第2步。 add path in System variable "C:\\Program Files (x86)\\Graphviz\\bin"
在系统变量“C:\\Program Files (x86)\\Graphviz\\bin”中添加路径
2.1 On the Windows taskbar, right-click the Windows icon and select System. 2.1 在 Windows 任务栏上,右键单击 Windows 图标并选择系统。
2.2 In the Settings window, under Related Settings, click Advanced system settings. 2.2 在“设置”窗口的“相关设置”下,单击“高级系统设置”。
2.3 On the Advanced tab, click Environment Variables. 2.3 在高级选项卡上,单击环境变量。
step3.第三步。 add below lines in my code
在我的代码中添加以下几行
import os
import graphviz
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz/bin/'
graph_data = "your graph data"
fie_ext = 'png'
temp_img = 'temp_file'
temp_img_name = "".join([temp_img, '.'+fie_ext])
my_graph= graphviz.Source(graph_data)
my_graph.render(temp_img,format=fie_ext, view=False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.