2

I have only recently started using Python 3.5 on my mac, which is running Yosemite, and I am trying to use the module networkx to compile and generate some visuals for graphics/network models. I don't have all that much programming experience so I apologise if I leave out any details.

I have successfully installed networkx (am able to use commands therefrom) but am currently struggling to install one of the optional modules that facilitates the generations of plots: GraphViz. I tried to install GraphViz via running through the command prompt the setup.py install commands but GraphViz installation seemingly requires another module, PyDot (PyDot2 to be more specific: pydot2-1.0.33-py3.5.egg.info). Therein lies the problem because I cannot seem to get PyDot to work correctly - I keep getting the following error when running the networkx command that uses PyDot (test2.py is a test graphics model):

Traceback (most recent call last):
  File "/Users/mainuser/Downloads/test2.py", line 6, in <module>
    nx.draw_graphviz(G)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/networkx/drawing/nx_pylab.py", line 982, in draw_graphviz
    pos = nx.drawing.graphviz_layout(G, prog)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/networkx/drawing/nx_pydot.py", line 257, in graphviz_layout
    return pydot_layout(G=G,prog=prog,root=root,**kwds)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/networkx/drawing/nx_pydot.py", line 277, in pydot_layout
    D=P.create_dot(prog=prog)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pydot.py", line 1802, in <lambda>
    lambda f=frmt, prog=self.prog : self.create(format=f, prog=prog))
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pydot.py", line 1966, in create
    self.write(tmp_name)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pydot.py", line 1895, in write
    dot_fd = file(path, "w+b")
NameError: name 'file' is not defined

After doing some research and playing around I feel like the issue is that the version of PyDot that I installed is not compatible with Python 3.5. However, I don't understand how this could be the case since I installed PyDot2 which says explicitly that it is compatible with Python 3+.

Any insight or directions would be much appreciated!

J Coates
  • 21
  • 3

1 Answers1

0

I noticed this issue and published a Python 3 compatible version on PyPi. The reason is that pydot/pydot2 uses functionalities that is removed in Python 3 already.

For Linux systems for Python 3.x, try:

pip3 install pydot3

Or in general for Python 2.x, try:

pip install pydot3

Log0
  • 145
  • 1
  • 8