在jupyter笔记本上运行gvmagic扩展,返回FileNotFounError

时间:2017-06-30 19:58:03

标签: ipython anaconda jupyter-notebook python-3.5 ipython-magic

我正在Windows 10计算机上使用Anaconda 2.5.0(64位)中的jupyter笔记本开发Python 3.5.3。我正在尝试使用名为'gvmagic'的扩展名,用于查看图表。扩展似乎加载,但返回FileNotFoundError而不是图形。

我的输入代码是(注意:'visualize_de_bruijn_graph'是一个自定义代码,用于根据字符串构建de Bruijn图形):

dbg = visualize_de_bruijn_graph('ACGCGTCG', 3)
print(dbg)

返回图表:

digraph "DeBruijn Graph" {
 CG [label="CG"] ;
 TC [label="TC"] ;
 GC [label="GC"] ;
 AC [label="AC"] ;
 GT [label="GT"] ;
 AC -> CG ;
 CG -> GC ;
 GC -> CG ;
 CG -> GT ;
 GT -> TC ;
 TC -> CG ;
}

尝试使用以下代码可视化图形:

%load_ext gvmagic
%dotstr dbg

返回以下错误。我无法弄清楚丢失了哪个文件,因为引用的所有文件都是它们所假设的位置。

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-17-d138faf6c47c> in <module>()
----> 1 get_ipython().magic('dotstr dbg')

C:\Users\username\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in magic(self, arg_s)
   2161         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2162         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2163         return self.run_line_magic(magic_name, magic_arg_s)
   2164 
   2165     #-------------------------------------------------------------------------

C:\Users\username\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line)
   2082                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2083             with self.builtin_trap:
-> 2084                 result = fn(*args,**kwargs)
   2085             return result
   2086 

<decorator-gen-126> in dotstr(self, line)

C:\Users\username\Anaconda3\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    194 
    195         if callable(arg):

C:\Users\username\Anaconda3\lib\site-packages\IPython\extensions\gvmagic.py in dotstr(self, line)
     50     @line_magic
     51     def dotstr(self, line):
---> 52         self._from_str(line, 'dot')
     53 
     54     @line_magic

C:\Users\username\Anaconda3\lib\site-packages\IPython\extensions\gvmagic.py in _from_str(self, line, layout_engine)
    151     def _from_str(self, line, layout_engine):
    152         s = self.shell.ev(line)
--> 153         data = run_graphviz(s, layout_engine)
    154         if data:
    155             display_svg(data, raw=True)

C:\Users\username\Anaconda3\lib\site-packages\IPython\extensions\gvmagic.py in run_graphviz(s, layout_engine)
     30     cmd = ['dot', '-Tsvg', '-K', layout_engine]
     31 
---> 32     dot = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
     33     stdoutdata, stderrdata = dot.communicate(s.encode('utf-8'))
     34     status = dot.wait()

C:\Users\username\Anaconda3\lib\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)
    674                                 c2pread, c2pwrite,
    675                                 errread, errwrite,
--> 676                                 restore_signals, start_new_session)
    677         except:
    678             # Cleanup if the child failed starting.

C:\Users\username\Anaconda3\lib\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, unused_restore_signals, unused_start_new_session)
    953                                          env,
    954                                          cwd,
--> 955                                          startupinfo)
    956             finally:
    957                 # Child is launched. Close the parent's copy of those pipe

FileNotFoundError: [WinError 2] The system cannot find the file specified

1 个答案:

答案 0 :(得分:0)

您必须在PC上安装Graphviz软件。例如,对于Windows,请下载此https://graphviz.gitlab.io/_pages/Download/Download_windows.html

在IPython会话中,您必须指向安装位置,例如:

import os

os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin'

%load_ext gvmagic

dbg = visualize_de_bruijn('ACGCGTCG', 3)

%dotstr dbg

现在它应该对您有效,就像对我一样!您可能可以在PC上设置PATH变量,而不必每次都在IPython内部进行设置。

相关问题