ere*_*ipS 4 python installation pip graphviz python-3.x
所以我已经在Windows 10计算机上安装了Python 3.6一段时间了,今天我才通过admin命令行通过以下命令下载并安装了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)
Run Code Online (Sandbox Code Playgroud)
但是不幸的是,当我尝试从命令行运行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
Run Code Online (Sandbox Code Playgroud)
请注意,在安装Graphviz 2.38之后,我所询问的内容似乎与以下问题非常相似: “ RuntimeError:确保Graphviz可执行文件在系统路径上”
但是由于某种原因,将这些路径(在上面的链接中的解决方案中建议)添加到系统变量中是行不通的,而且我也不知道为什么!我也尝试在添加路径后重新启动计算机,但仍然没有成功。见下图:
尽管另一个建议的解决方案是在我的Python代码之前添加了以下几行,但确实有效:
import os
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'
Run Code Online (Sandbox Code Playgroud)
但这是问题所在:我不明白为什么向环境变量中添加变量无效,这是我的主要关注点。 所以我的问题是这样的:为什么在Python脚本之前添加这些代码行却有效,但是更改环境变量却没有呢? 我需要做些什么才能使脚本运行而不在前面添加这些代码行?
SET设置PATH环境变量后,在cmd窗口中键入内容时,您能否发布您获得的输出?
是否包含C:/Program Files (x86)/Graphviz2.38/bin/?
在更新的环境变量生效之前,必须重新启动cmd窗口!
| 归档时间: |
|
| 查看次数: |
14628 次 |
| 最近记录: |