我正在尝试使用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
如何解决此错误?
答案 0 :(得分:0)
您确定您的用户有权在其他计算机上写入/tmp/
吗?试试touch /tmp/state.svg
。如果失败则这是unix权限的问题。您需要chmod
/tmp/
文件夹,无论用户拥有它(可能是root
)。或者,尝试更改您要写入的路径;也许只需使用您的主目录~/state.svg
。