【问题标题】:Python program can not import dot parserPython程序无法导入点解析器
【发布时间】:2015-04-16 14:12:05
【问题描述】:

我正在尝试从命令行运行模拟 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

我已经尝试过针对堆栈溢出时类似的question 建议的解决方案。我仍然得到同样的错误。这是我正在使用的包版本和我的 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 的方式可能有问题。

【问题讨论】:

    标签: python numpy graphviz pydot


    【解决方案1】:

    您没有使用最新版本的 pydot 有什么特别的原因吗?

    1.0.2 的这个版本看起来正好解决了这个问题:

    https://code.google.com/p/pydot/source/diff?spec=svn10&r=10&format=side&path=/trunk/pydot.py

    参见第 722 行。

    【讨论】:

    • 版本 1.0.28 解决了这个问题。谢谢!!!但是,当我运行我的程序时,我仍然收到消息“无法导入 dot_parser,无法加载点文件”。
    • 是的,错误仍然来自 1.0.28 的 pydot。我通过删除执行“import dot_parser”的行修改了 pydot.py,一切都很好。
    【解决方案2】:

    升级我的 pyparsing 模块解决了这个问题。试试:

    pip install --upgrade pyparsing
    

    【讨论】:

      猜你喜欢
      • 2022-06-16
      • 2021-10-26
      • 2016-05-01
      • 2022-07-28
      • 2021-03-18
      • 2019-04-09
      • 2023-01-09
      • 2018-03-23
      • 2017-10-23
      相关资源
      最近更新 更多