问题描述
当我用 pydot 运行一个非常简单的代码时
When I run a very simple code with pydot
import pydot
graph = pydot.Dot(graph_type='graph')
for i in range(3):
edge = pydot.Edge("king", "lord%d" % i)
graph.add_edge(edge)
vassal_num = 0
for i in range(3):
for j in range(2):
edge = pydot.Edge("lord%d" % i, "vassal%d" % vassal_num)
graph.add_edge(edge)
vassal_num += 1
graph.write_png('example1_graph.png')
它向我打印错误信息:
Couldn't import dot_parser, loading of dot files will not be possible.
我使用的是 python 2.7.3
I'm using python 2.7.3
推荐答案
pydot >= 1.1
的答案:
6dff94 已修复(上游)pydot
的不兼容性/a>,因此 pydot >= 1.1
将 与 pyparsing >= 1.5.7.
The incompatibility of (upstream) pydot
has been fixed by 6dff94b3f1, and thus pydot >= 1.1
will be compatible with pyparsing >= 1.5.7
.
适用于pydot 的答案:
对于遇到此问题的任何其他人,这是由于 pyparsing 从 1.x 到 2.x 版本的更改.要使用 pip 安装 pydot,请先安装旧版本的 pyparsing:
For anyone else who comes across this, it is due to the changes in pyparsing from 1.x to the 2.x release.To install pydot using pip, first install the older version of pyparsing:
pip install pyparsing==1.5.7
pip install pydot==1.0.28
如果你没有使用 pip
安装 pyparsing
,而是使用了 setup.py
,那么看看这个 卸载包.谢谢@qtips.
If you did not install pyparsing
using pip
, but instead used setup.py
, then have a look at this solution to uninstall the package. Thanks @qtips.
这篇关于pydot 和 graphviz 错误:无法导入 dot_parser,无法加载点文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!