0

I am trying to generate a chart with pygraphviz in Python 3.

It works on my machine with this Anacondas version:

Python 3.3.5 |Continuum Analytics, Inc.| (default, Jun  4 2015, 15:22:11) 

It returns a PermissionError when I run it from a different machine running:

Python 3.5.1 |Continuum Analytics, Inc.| (default, Dec  7 2015, 11:17:45) 

The code is:

from IPython.display import SVG
import pygraphviz as pgv
from IPython.display import display

G = pgv.AGraph(directed=True)

G = pgv.AGraph(compound=True,directed=True)

sub = G.add_subgraph( name='cluster_1', label='Restaurant Open', rank='same')

sub.add_node( 'initial', label='')
sub.add_node('Loitering')
sub.add_edge('initial','Loitering')

G.draw('/tmp/state.svg', prog='dot')
display(SVG(fn)) 

The Exception is:

---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
<ipython-input-1-762f54aa869d> in <module>()
     16 
     17 fn='state.svg'
---> 18 G.draw('/tmp/state.svg', prog='dot')
     19 display(SVG(fn))

/home/jon/miniconda3/lib/python3.5/site-packages/pygraphviz/agraph.py in draw(self, path, format, prog, args)
   1472             args = ' '.join([args, "-T" + format])
   1473 
-> 1474         data = self._run_prog(prog, args)
   1475 
   1476         if path is not None:

/home/jon/miniconda3/lib/python3.5/site-packages/pygraphviz/agraph.py in _run_prog(self, prog, args)
   1314                              stdout=subprocess.PIPE,
   1315                              stderr=subprocess.PIPE,
-> 1316                              close_fds=False)
   1317         (child_stdin,
   1318          child_stdout,

/home/jon/miniconda3/lib/python3.5/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds)
    948                                 c2pread, c2pwrite,
    949                                 errread, errwrite,
--> 950                                 restore_signals, start_new_session)
    951         except:
    952             # Cleanup if the child failed starting.

/home/jon/miniconda3/lib/python3.5/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1542                             else:
   1543                                 err_msg += ': ' + repr(orig_executable)
-> 1544                     raise child_exception_type(errno_num, err_msg)
   1545                 raise child_exception_type(err_msg)
   1546 

PermissionError: [Errno 13] Permission denied

How can I resolve this error?

Ginger
  • 8,320
  • 12
  • 56
  • 99

1 Answers1

0

Are you sure your user has permissions to write to /tmp/ on that other machine? Try touch /tmp/state.svg. If that fails then this is an issue with the unix permissions. You'll need to chmod the /tmp/ folder with whatever user owns it (probably root). Alternatively, try changing the path you are writing to; perhaps just use your home directory ~/state.svg.

Paul
  • 5,473
  • 1
  • 30
  • 37
  • I tried touch /tmp/state.svg and it worked. To try to resolve the issue, I reinstalled PyCharm and Anaconda, but now have another problem... – Ginger Jul 12 '16 at 06:20
  • The problem morphed into this when I tried reinstalling Pycharm and Anaconda: http://stackoverflow.com/questions/38321442/oserror-when-loading-shared-libraries-with-pygraphviz – Ginger Jul 12 '16 at 06:28