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 に答える