0

I am developing Python 3.5.3 using the jupyter notebook in Anaconda 2.5.0 (64-bit) on a Windows 10 machine. I am trying to use an extension called 'gvmagic', which is used for viewing graphs. The extension seems to load, but returns a FileNotFoundError instead of a graph.

My input code is (Note: 'visualize_de_bruijn_graph' is a custom code that builds a de Bruijn graph from a string):

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

Which returns graph:

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

Trying to visualize the graph with the following code:

%load_ext gvmagic
%dotstr dbg

returns the error below. I cannot figure out what file is missing, as all the files referenced are where they are suppose to be.

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
gwilymh
  • 415
  • 1
  • 7
  • 20
  • Do you have `dot` installed? – darthbith Jul 01 '17 at 15:26
  • I afraid don't know. Do you know how I could check this? Is `dot` a package or a function or class within a package? Where in the IPython directory should the package be located (e.g. `C:\Users\username\Anaconda3\Lib\site-packages\IPython`)? – gwilymh Jul 03 '17 at 23:53
  • Note: I initially installed `graphvis` with the command `conda install graphvis`. I tried to use `conda install` to install `gvmagic`, but got the error `package missing in current win-64 channels`. I therefore installed `gvmagic` with the command `pip install -t 'C:\Users\username\Anaconda3\Lib\site-packages\IPython\extensions' gvmagic` – gwilymh Jul 04 '17 at 00:03
  • First, `graphviz` is spelled with a `z`, not an `s`. Second, it is available from http://www.graphviz.org/. Third, `dot` is one of the executables distributed with Graphviz, not a Python package (although, confusingly, there is a Python package with the same name that provides an interface to the true Graphviz language). You should be able to type `dot` at a regular command prompt (not Python) and get an output. – darthbith Jul 04 '17 at 03:50
  • 1
    Good job finding the typo I made twice in writing `graphvis` instead of `graphviz`. – gwilymh Jul 05 '17 at 17:52
  • I verified that `dot` is installed. – gwilymh Jul 05 '17 at 18:19
  • I thought the problem might be with `graphviz`, because when I initially installed it I got an error similar to the one described in this post: https://stackoverflow.com/questions/41898928/weird-repeated-sequence-printed-to-console-when-installing-packages-through-cond I followed the instructions in the post to update `pip` and the `cryptography` package: `pip install --upgrade pip; pip install cryptography>=1.7 --upgrade -t C:\Users\username\Anaconda3\Lib\site-packages; conda install graphviz`. `graphviz` installed without error, but the `FileNotFound` error persists. – gwilymh Jul 05 '17 at 18:29
  • Can you run `dot` from a regular command prompt? The error indicates (to my reading) that `dot` can't be found on the PATH – darthbith Jul 05 '17 at 23:33

1 Answers1

0

You have to install the Graphviz software on your PC. For Windows, for example, download this https://graphviz.gitlab.io/_pages/Download/Download_windows.html.

In your IPython session, you have to point to the install location, for example:

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

And now it should work for you, just as it does for me! You can probably set the PATH variable on your PC instead of having to do it inside IPython each time.

kenlukas
  • 3,616
  • 9
  • 25
  • 36