Python program can not import dot parser

Haider picture Haider · Feb 16, 2015 · Viewed 7.9k times · Source

I am trying to run a huge evolution simulating python software from the command line. The software is dependent on the following python packages:

1-networkX

2-pyparsing

3-numpy

4-pydot

5-matplotlib

6-graphviz

The error I get is this:

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

I have already tried the solution suggested for a similar question on stack overflow. I still get the same error. Here are the package versions I am using and my python version.

  • I'm using python 2.7.6
  • typing the command which -a python yields the result: "/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)

Any ideas? Seeing that the solution to similar questions is not working for me, I think the problem might be more fundamental in my case. Something wrong with the way I installed my python perhaps.

Answer

robert_x44 picture robert_x44 · Feb 16, 2015

Any particular reason you're not using the newest version of pydot?

This revision of 1.0.2 looks like it fixes exactly that problem:

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

See line 722.