在路径中找不到“dot.exe”。Python 上的 Pydot (Windows 7)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40632486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"dot.exe" not found in path. Pydot on Python (Windows 7)
提问by Dubraven93
I'm having trouble running Python's pydot on Windows 7.
我在 Windows 7 上运行 Python 的 pydot 时遇到问题。
I installed pydot with: conda install -c rmg pydot=1.2.2
我安装了pydot: conda install -c rmg pydot=1.2.2
I have graphviz installed under ../Program Files (x86)/Graphviz2.38/
我在下面安装了graphviz ../Program Files (x86)/Graphviz2.38/
When I run the following script I get an error saying
当我运行以下脚本时,我收到一条错误消息
"dot.exe" not found in path
"dot.exe" not found in path
import pydot
graph = pydot.Dot(graph_type='digraph')
node_a = pydot.Node("Node A", style="filled", fillcolor="red")
node_b = pydot.Node("Node B", style="filled", fillcolor="green")
node_c = pydot.Node("Node C", style="filled", fillcolor="#0000ff")
node_d = pydot.Node("Node D", style="filled", fillcolor="#976856")
graph.add_node(node_a)
graph.add_node(node_b)
graph.add_node(node_c)
graph.add_node(node_d)
graph.add_edge(pydot.Edge(node_a, node_b))
graph.add_edge(pydot.Edge(node_b, node_c))
graph.add_edge(pydot.Edge(node_c, node_d))
graph.add_edge(pydot.Edge(node_d, node_a, label="and back we go again", labelfontcolor="#009933", fontsize="10.0", color="blue"))
graph.write_png('example2_graph.png')
Exception: "dot.exe" not found in path.
I have tried this solution: Permanently adding a file path to sys.path in Python, by adding the my-paths.pth
file with a line pointing to
../Graphiv2.38/bin/
where the dot.exe
file is located. But I still get the error.
我已经尝试过这个解决方案:通过添加带有指向文件所在位置的行的文件,
在 Python 中永久添加文件路径到 sys.path。但我仍然收到错误。my-paths.pth
../Graphiv2.38/bin/
dot.exe
What else can I try?
我还能尝试什么?
回答by Ernest S Kirubakaran
I followed the instructions given in this blog.
我按照此博客中给出的说明进行操作。
Then I installed graphviz from hereand added C:\Program Files (x86)\Graphviz2.38\bin to PATH
.
然后我从这里安装了 graphviz并将 C:\Program Files (x86)\Graphviz2.38\bin 添加到PATH
.
Next I did:
接下来我做了:
conda install pydot-ng
And finally in my notebook I added the two lines below.
最后在我的笔记本中,我添加了下面的两行。
import os
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'
回答by jmir
Type conda install pydot graphviz
in cmd, and then add the executables location directory C:\Anaconda3\pkgs\graphviz-2.38-hfd603c8_2\Library\bin\graphviz
to your system path variable. That works!
键入conda install pydot graphviz
cmd,然后将可执行文件位置目录添加C:\Anaconda3\pkgs\graphviz-2.38-hfd603c8_2\Library\bin\graphviz
到系统路径变量中。那个有效!
回答by Rajneesh Aggarwal
Don't use the following command if you are on Python 3:
如果您使用的是 Python 3,请不要使用以下命令:
conda install pydot-ng
This will take your installation to Python 2.7
这会将您的安装带到 Python 2.7
Use instead
改用
conda install graphviz
回答by Rabash
Other solutions didn't work for me, and I figured out pydottried to run a hardcoded dot.bat
so I just created dot.bat
wrapper nearby dot.exe
and it worked:
其他解决方案对我不起作用,我发现pydot试图运行硬编码,dot.bat
所以我只是在dot.bat
附近创建了包装器dot.exe
并且它起作用了:
@echo off
dot %*
回答by Gret
Using django-extensionsto generate the model graph for your Django application, I did this and it worked:
使用django-extensions为您的 Django 应用程序生成模型图,我这样做了并且它有效:
pip install django-extensions
pip install pyparsing
pip install graphviz
pip install pydot
conda install graphviz
Add django-extensions
to you INSTALLED_APPS
and then add C:\Program Files\Anaconda3\pkgs\graphviz-2.38.0-4\Library\bin\graphviz
to my system path variable.
Then finally and normally:
添加django-extensions
到你INSTALLED_APPS
然后添加C:\Program Files\Anaconda3\pkgs\graphviz-2.38.0-4\Library\bin\graphviz
到我的系统路径变量。最后,通常:
python manage.py graph_models -a -g -o pic.png
回答by ToxicGLaDOS
I was having trouble with this and found out that if you're using the Visual Studio Code integrated command line then you should make sure to restart Visual Studio Code (you might need to only restart the command line) otherwise the PATH changes won't take place...
我遇到了这个问题,发现如果您使用的是 Visual Studio Code 集成命令行,那么您应该确保重新启动 Visual Studio Code(您可能只需要重新启动命令行),否则 PATH 更改不会发生...
回答by Romain Cendre
In this kind of cases, when resources are not found by programs on your system, follow these quick steps:
在这种情况下,当系统上的程序找不到资源时,请执行以下快速步骤:
- Run a simple command prompt, type and execute the needed command (can be 'dot.exe')
- If yes, your system is nicely configured and perhaps due to a hard configured way in your code, executables are not found (need a specific location for files to be found for instance: program check for C:\Program Files\Anaconda3\pkgs\graphviz and you put binaries in C:\Program Files\graphviz).
- If no, you need to add it manually. In environment variable add the directory that contains the binaries (for instance 'my_location\graphviz\bin'). If you need it for whole users of the computer, put it in the system 'Path' (need to disconnect the users accounts to be considered), else in the user 'Path' (need to reopen the needed program). Then check it by re-opening a command prompt and typing the command.
- 运行一个简单的命令提示符,键入并执行所需的命令(可以是“dot.exe”)
- 如果是,则您的系统配置良好,并且可能由于代码中的硬配置方式,找不到可执行文件(需要特定位置才能找到文件,例如:程序检查 C:\Program Files\Anaconda3\pkgs\ graphviz 并将二进制文件放在 C:\Program Files\graphviz 中)。
- 如果没有,则需要手动添加。在环境变量中添加包含二进制文件的目录(例如“my_location\graphviz\bin”)。如果您需要为计算机的整个用户提供它,请将其放在系统“路径”中(需要断开用户帐户才能考虑),否则放在用户“路径”中(需要重新打开所需的程序)。然后通过重新打开命令提示符并键入命令来检查它。
If it's not working... you mistyped something =)
如果它不起作用......你打错了一些东西=)
Some advices: Rapid Environment Editor is pretty cool for configuring windows environment variables ;)
一些建议:Rapid Environment Editor 非常适合配置 Windows 环境变量;)
Have a nice day!
祝你今天过得愉快!
回答by Farzad Vertigo
On Ubuntu 18.04 installing the binaries with sudo apt-get install graphviz
led to dot
being placed under /usr/bin/dot
(it might go to /usr/local/bin/dot
per their installation guide).
After doing:
在 Ubuntu 18.04 上安装二进制文件,sudo apt-get install graphviz
导致dot
被放置/usr/bin/dot
(它可能会/usr/local/bin/dot
按照他们的安装指南进行)。做完之后:
pip3 install pydot-ng
and adding the following lines (similar to @Ernest's answer in Linux) to the script it worked:
并将以下几行(类似于 Linux 中的@Ernest 的回答)添加到它工作的脚本中:
import os
os.environ["PATH"] += os.pathsep + "/usr/bin/dot"