python - 如何确保 Graphviz 可执行文件位于我系统的 PATH 中?
问题描述
我正在使用 Python 3 在 Sublime Text 3 上使用 Graphviz。当我运行此代码时:
data = tree.export_graphviz(dtGini[55], out_file = None)
graph = graphviz.Source(data)
graph.render("testingthis")
我收到这些错误:
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
看起来它找不到它需要的文件。在 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"
}
我的控制面板中有这些环境变量:
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
在 Anaconda 提示符中,当我输入 Python 时,按回车键,然后输入“import graphviz”,我没有收到任何错误。在 Sublime Text 3 中,如果我只有一个像 graph.py 这样的文件
import graphviz
它执行没有任何错误。
关于如何解决这个问题的任何想法?它快把我逼疯了。谢谢!
解决方案
在安装 Graphviz 2.38 后,我遵循了@aprameyo roy在此处发布的解决方案 > “RuntimeError:确保 Graphviz 可执行文件位于系统路径上”
所需的系统路径在我的 PC 上进行了一些查找——我使用 Ananconda 安装了 graphviz 包。
将这两个命令添加到我的 jupyter notebook 解决了这个问题 - 将 C:/ 地址更改为您的安装位置:
(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/'
推荐阅读
- python - PyQt5:如果 QLineEdit 为空,如何输入默认值?
- json - 使用 Nuxt 中的 Fetch 使用静态 json 文件创建博客。如何使用 slug 获取特定节点的内容?
- python - ModuleNotFoundError:没有名为“rest_framework.response”的模块
- android - Flutter:在 VS Code Mac Catalina 10.15.7 上的 Android/iOS 模拟器中,项目将无法连接到 Firebase/Firestore
- python - 熊猫数据框为总计创建带有水平边框的html表格
- android - Android Listview 删除复选框 Kotlin
- javascript - Node JS 和 JIMP:没有匹配的构造函数重载
- xml - 如何使用 XSLT 替换 XML 中的前缀和命名空间
- c - 如何修复“可变大小的对象可能未初始化”?
- jdbc - Spark - 尝试写入 Redshift 时出现只读错误