0

我正在尝试在 Python 3 中使用 pygraphviz 生成图表。

它可以在我的机器上使用这个 Anacondas 版本:

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

当我从另一台运行的机器上运行它时,它会返回一个 PermissionError:

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

代码是:

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)) 

例外是:

---------------------------------------------------------------------------
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

如何解决此错误?

4

1 回答 1

0

您确定您的用户有权/tmp/在另一台机器上写入吗?试试touch /tmp/state.svg。如果失败,则这是 unix 权限的问题。无论用户拥有它(可能) ,您都需要chmod该文件夹。或者,尝试更改您正在写入的路径;也许只是使用您的主目录。/tmp/root~/state.svg

于 2016-07-11T15:45:26.060 回答