python-3.xpygraphvizgraph-drawing

Why does draw() in pygraphviz/agraph not work on the server (but locally)?


I have a Python app using Pygraphviz that works fine locally, but on the server the draw function throws an error. It happens in make_svg. The following lines are the relevant part of the errors I get. (The full trail is here.)

File "/path/to/app/utils/make_svg.py", line 17, in make_svg
  prog='dot'
File "/path/to/pygraphviz/agraph.py", line 1477, in draw
  fh = self._get_fh(path, 'w+b')
File "/path/to/pygraphviz/agraph.py", line 1506, in _get_fh
  fh = open(path, mode=mode)
FileNotFoundError: [Errno 2] No such file or directory: 'app/svg_files/nope.svg'

Logging type(g) gives <class 'pygraphviz.agraph.AGraph'> as expected.

I work in a virtualenv in a mod_wsgi 4.6.5/Python3.7 environment on a Webfaction server.
Locally I use a virtualenv with Python 3.5.
The version of Pygraphviz is 1.3.1.
(First I had 1.5 on the server. The error was exactly the same, except for the line numbers.)

What can I do?

The same error is described in this bug report from last year.
I don't get which directory I am supposed to create. svg_files exists and has rights 777.

The draw function at the end of make_svg should create the SVG.
(And at the end of extract_coordinates_from_svg the file is removed again.)
The file name is a hash created in connected_dag (svg_name).


Solution

  • On the server app/svg_files seems not to describe the same place as locally.
    I defined the path unambiguously, and now it works.

    file_path = '{grandparent}/svg_files/{name}.svg'.format(
        grandparent=os.path.dirname(os.path.dirname(__file__)),
        name=name
    )
    g.draw(file_path, prog='dot')