可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I downloaded Graphviz 2.38
MSI version and installed under folder C:\Python34
, then I run pip install Graphviz
, everything went well. In system's path I added C:\Python34\bin
. When I tried to run a test script, in line filename=dot.render(filename='test')
, I got a message
RuntimeError: failed to execute ['dot', '-Tpdf', '-O', 'test'], make sure the Graphviz executables are on your systems' path
I tried to put "C:\Python34\bin\dot.exe"
in system's path, but it didn't work, and I even created a new environment variable "GRAPHVIZ_DOT"
with value "C:\Python34\bin\dot.exe"
, still not working. I tried to uninstall Graphviz and pip uninstall graphviz, then reinstall it and pip install again, but nothing works.
The whole traceback message is:
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
Does anybody have any experience with it?
回答1:
You should install the graphviz package in your system (not just the python package). On Ubuntu you should try:
sudo apt-get install graphviz
回答2:
This one solved the problem for me on MAC:
brew install graphviz
回答3:
import os
os.environ["PATH"] += os.pathsep + 'D:/Program Files (x86)/Graphviz2.38/bin/'
In windows just add these 2 lines in the beginning, where 'D:/Program Files (x86)/Graphviz2.38/bin/' is replaced by the address of where your bin file is.
That solves the problem.
回答4:
For Windows:
- Install windows package from: https://graphviz.gitlab.io/_pages/Download/Download_windows.html
- Install python
graphviz
package
- Add
C:\Program Files (x86)\Graphviz2.38\bin
to User path
- Add
C:\Program Files (x86)\Graphviz2.38\bin\dot.exe
to System Path
This worked for me!
回答5:
Just add below to your Environmental Variable(system) PATH
on Windows
C:\Program Files (x86)\Graphviz2.38\bin
there, you can find .exe files
If not work
Find Graphviz2.38/bin folder in your Program Files not in python lib
Then, add to your PATH
It's important to find a folder where .exe files exist
回答6:
OSX Sierra, Python 2.7, Graphviz 2.38
Using pip install graphviz
and conda install graphviz
BOTH resolves the problem.
pip
only gets path problem same as yours and conda
only gets import error.
回答7:
Try conda install graphviz
. I had the same problem, I resolved it by mentioned command in MacOS.
回答8:
Try using:
conda install python-graphviz
The graphviz executable sit on a different path from your conda directory, if you use pip install graphviz
.
回答9:
After you've installed the package (link if you haven't), add the path to dot.exe as a new system variable.
Default path is:
C:\Program Files (x86)\Graphviz2.38\bin\dot.exe
回答10:
I had the same issue on Linux with Jupyter.
To solve it I've added the dot library to python sys.path
First: check if dot
is installed,
Then:
find his path whereis dot
-> /local/notebook/miniconda2/envs/ik2/bin/dot
Finally in python script :
sys.path.append("/local/notebook/miniconda2/envs/ik2/bin/dot")
回答11:
First, you should use pip install, and then download another package in http://www.graphviz.org/Download_windows.php
and add the install location into the environmental path, then it works.
回答12:
I had the same error message on Mac OS (El Capitan), using the PyCharm IDE.
I had installed Graphviz using brew, as recommended in RZK's answer, and installed the graphviz python package using PyCharm (I could check Graphviz was installed correctly by trying dot -V
in a terminal and getting: dot - graphviz version 2.40.1 (20161225.0304)
).
Yet I was still getting the error message when trying to call Graphviz from PyCharm.
I had to add the path /usr/local/bin in PyCharm options, as recommended in the answer to this question to resolve the problem.
回答13:
For Linux users who don't have root access and hence can't use sudo
command as suggested in other answers...
First, activate your conda virtual-environment (if you want to use one) by:
source activate virtual-env-name
Then install graphviz, even if you have already done it using pip:
conda install graphviz
then copy the result of the following command:
whereis dot
In my case, its output is:
/home/nader/anaconda2/bin/dot
and add it to your PATH variable. Just run the command below
nano ~/.bashrc
and add these lines to the end of the opened file:
PATH="/home/username/anaconda2/bin/dot:$PATH"
export PATH
now press Ctrl+O and then Ctrl+X to save and exit.
Problem should be solved by now.
Pycharm users, please note: Pycharm does not always see the PATH variable the same as your terminal. This solution does not work for Pycharm, and maybe other IDEs. But you can fix this by adding this line of code:
os.environ["PATH"] += os.pathsep + '/home/nader/anaconda2/bin'
to your python program. Do not forget to
import os
first :)
Edit: If you don't want to use conda, you can still install graphviz from here without any root permissions and add the bin folder to your PATH variable. I didn't test this.
回答14:
conda install python-graphviz
For Windows, install the Python Graphviz which will include the executables in the path.