Python程序无法导入dot解析器

4
我想要从命令行运行一个巨大的演化模拟Python软件。该软件依赖以下Python包:
1. networkX
2. pyparsing
3. numpy
4. pydot
5. matplotlib
6. graphviz
我遇到的错误是:
Couldn't import dot_parser, loading of dot files will not be possible.
initializing with file= initAdapt.py in model dir= ./Test_adaptation//
Traceback (most recent call last):
  File "run_evolution.py", line 230, in <module>
    gr.write_dot( os.path.join(test_output_dir, 'test_net.dot') )
  File "/Library/Python/2.7/site-packages/pydot.py", line 1602, in <lambda>
    lambda path, f=frmt, prog=self.prog : self.write(path, format=f,          prog=prog))
  File "/Library/Python/2.7/site-packages/pydot.py", line 1696, in write
    dot_fd.write(self.create(prog, format))
  File "/Library/Python/2.7/site-packages/pydot.py", line 1740, in create
    self.write(tmp_name)
  File "/Library/Python/2.7/site-packages/pydot.py", line 1694, in write
    dot_fd.write(self.to_string())
  File "/Library/Python/2.7/site-packages/pydot.py", line 1452, in to_string
    graph.append( node.to_string()+'\n' )
  File "/Library/Python/2.7/site-packages/pydot.py", line 722, in to_string
    node_attr.append( attr + '=' + quote_if_necessary(value) )
TypeError: cannot concatenate 'str' and 'int' objects

我已经尝试了stackoverflow上类似问题的解决方案,但仍然出现相同的错误。这是我使用的软件包版本和Python版本。

  • 我使用的是Python 2.7.6
  • 输入命令which -a python的结果为:“/usr/bin/python”。

1-pyparsing (1.5.7)

2-pydot (1.0.2)

3-matplotlib (1.3.1)

4-graphviz (0.4.2)

5-networkx (0.37)

6-numpy (1.8.0rc1)

有什么想法吗?鉴于类似问题的解决方案对我不起作用,我认为问题可能更根本。也许是我安装Python的方式有问题。

2个回答

3

版本1.0.28修复了问题。谢谢!尽管如此,当我运行程序时,仍然会收到“无法导入dot_parser,将无法加载dot文件”的消息。 - Haider
是的,错误仍然来自1.0.28的pydot。我通过删除执行“import dot_parser”的行来修改了pydot.py,现在一切都很好。 - Peter Teoh

1
升级我的pyparsing模块解决了这个问题。请尝试:
pip install --upgrade pyparsing

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接