问题
I'm having trouble running Python's pydot on Windows 7.
I installed pydot with: conda install -c rmg pydot=1.2.2
I have graphviz installed under ../Program Files (x86)/Graphviz2.38/
When I run the following script I get an error saying
"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.
What else can I try?
回答1:
I followed the instructions given in this blog.
Then I installed graphviz from here and added C:\Program Files (x86)\Graphviz2.38\bin to 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/'
回答2:
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!
回答3:
Don't use the following command if you are on Python 3:
conda install pydot-ng
This will take your installation to Python 2.7
Use instead
conda install graphviz
回答4:
Using django-extensions to generate the model graph for your Django application, I did this and it worked:
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:
python manage.py graph_models -a -g -o pic.png
回答5:
Other solutions didn't work for me, and I figured out pydot tried to run a hardcoded dot.bat
so I just created dot.bat
wrapper nearby dot.exe
and it worked:
@echo off
dot %*
回答6:
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...
回答7:
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.
If it's not working... you mistyped something =)
Some advices: Rapid Environment Editor is pretty cool for configuring windows environment variables ;)
Have a nice day!
来源:https://stackoverflow.com/questions/40632486/dot-exe-not-found-in-path-pydot-on-python-windows-7