所以我已经在我的Windows10计算机上安装了Python3.6有一段时间了,今天我通过管理命令行下载并安装了graphviz 0.8.2
(https://pypi.python.org/pypi/graphviz)包,其中包括:
pip3 install graphviz
在此之后,我下载了Graphviz 2.38 MSI安装程序文件,并在以下位置安装了该程序:
C:\Program Files (x86)\Graphviz2.38
所以我试着运行这个简单的Python程序:
from graphviz import Digraph
dot = Digraph(comment="The round table")
dot.node('A', 'King Arthur')
dot.node('B', 'Sir Bedevere the Wise')
dot.node('L', 'Sir Lancelot the Brave')
dot.render('round-table.gv', view=True)
但不幸的是,当我试图从命令行运行Python程序时,收到了以下错误:
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\graphviz\backend.py", line 124, in render
subprocess.check_call(args, startupinfo=STARTUPINFO, stderr=stderr)
File "C:\Program Files\Python36\lib\subprocess.py", line 286, in check_call
retcode = call(*popenargs, **kwargs)
File "C:\Program Files\Python36\lib\subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Program Files\Python36\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Program Files\Python36\lib\subprocess.py", line 997, 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 "D:\foldername\testing.py", line 11, in <module>
dot.render('round-table.gv', view=True)
File "C:\Program Files\Python36\lib\site-packages\graphviz\files.py", line 176, in render
rendered = backend.render(self._engine, self._format, filepath)
File "C:\Program Files\Python36\lib\site-packages\graphviz\backend.py", line 127, in render
raise ExecutableNotFound(args)
graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'round-table.gv'], make sure the Graphviz executables are on your systems' PATH
请注意,我所问的问题与这里所问的问题非常相似: "RuntimeError: Make sure the Graphviz executables are on your system's path" after installing Graphviz 2.38
但出于某种原因,将这些路径(在上面链接的解决方案中建议)添加到系统变量中是行不通的,我也不知道为什么!在添加路径之后,我也尝试重新启动计算机,但仍然没有成功。见下图:
尽管另一个建议的解决方案是在我的Python代码前面添加这几行代码,确实有效:
import os
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'
但问题是:我不明白为什么添加到环境变量不起作用,这是我最关心的问题。所以我的问题是:为什么在Python脚本前面添加这些代码行是有效的,但是更改环境变量却没有?在不在前面添加这些代码行的情况下,我需要做什么来运行我的脚本?
在设置了PATH环境变量后,在cmd窗口中键入
SET
时,您可以发布得到的输出吗?它是否包含
C:/Program Files (x86)/Graphviz2.38/bin/
?在更新的环境变量生效之前,必须重新启动cmd窗口!
相关问题 更多 >
编程相关推荐