jiffyclub/snakeviz

FileNotFoundError when running from jupyter kernel

pepicello opened this issue · 6 comments

I get a FileNotFoundError whenever I run snakeviz from a jupyter kernel, e.g.:

%snakeviz print('test')

It looks like it happens when trying to open the results. I noticed that it runs fine and saves the results to file. I also tried to run %snakeviz -t print('test') with similar results.

Traceback:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-8-02d47ac0b7c8> in <module>()
----> 1 get_ipython().run_line_magic('snakeviz', 'print('test')')

~\AppData\Local\Continuum\anaconda3\envs\xxx\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2129                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2130             with self.builtin_trap:
-> 2131                 result = fn(*args,**kwargs)
   2132             return result
   2133 

<decorator-gen-804> in snakeviz(self, line, cell)

~\AppData\Local\Continuum\anaconda3\envs\xxx\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

~\AppData\Local\Continuum\anaconda3\envs\xxx\lib\site-packages\snakeviz\ipymagic.py in snakeviz(self, line, cell)
     79             if _check_ipynb() and not ('t' in opts or 'new-tab' in opts):
     80                 print('Embedding SnakeViz in the notebook...')
---> 81                 sv = open_snakeviz_and_display_in_notebook(filename)
     82             else:
     83                 print('Opening SnakeViz in a new tab...')

~\AppData\Local\Continuum\anaconda3\envs\xxx\lib\site-packages\snakeviz\ipymagic.py in open_snakeviz_and_display_in_notebook(filename)
    127         return sv
    128 
--> 129     sv = _start_and_wait_when_ready()
    130     path = "/snakeviz/%s" % quote(filename, safe='')
    131     display(HTML(JUPYTER_HTML_TEMPLATE.format(

~\AppData\Local\Continuum\anaconda3\envs\xxx\lib\site-packages\snakeviz\ipymagic.py in _start_and_wait_when_ready()
    120         sv = subprocess.Popen(
    121             ['snakeviz', "-s", "-H", "0.0.0.0", "-p", port, filename],
--> 122             stdout=subprocess.PIPE, universal_newlines=True, env=environ)
    123         while True:
    124             line = sv.stdout.readline()

~\AppData\Local\Continuum\anaconda3\envs\xxx\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.

~\AppData\Local\Continuum\anaconda3\envs\xxx\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)
    955                                          env,
    956                                          cwd,
--> 957                                          startupinfo)
    958             finally:
    959                 # Child is launched. Close the parent's copy of those pipe

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

Versions:
snakeviz: 2.0.0
python: 3.5.6.final.0
OS: Windows 7 (64bit)

Thank you for your help!

Can you run just snakeviz directly in the same Anaconda environment? This seems to be saying that it can't find the snakeviz executable itself.

Regardless, IMO that code shouldn't be calling snakeviz, but rather something like [sys.executable, '-m', 'snakeviz']. That way it can be really sure it's using the same snakeviz from the same package. @jiffyclub , thoughts?

@embray That makes sense now that that's a supported way of calling snakeviz!

Can you run just snakeviz directly in the same Anaconda environment? This seems to be saying that it can't find the snakeviz executable itself.

Regardless, IMO that code shouldn't be calling snakeviz, but rather something like [sys.executable, '-m', 'snakeviz']. That way it can be really sure it's using the same snakeviz from the same package. @jiffyclub , thoughts?

Yes, I have no issues calling the executable, but the error message is slightly misleading as I thought for a while that snakeviz was crashing before producing the results. Maybe a warning would be better? Thanks!

Are you sure it's the same one though? I.e. does ~\AppData\Local\Continuum\anaconda3\envs\xxx\Scripts\snakeviz exist? And is it on your $PATH?

I just tried it myself in a conda env on Windows (Python 3.6 though) and it worked--I had it under ~\\miniconda3\\envs\\test\\Scripts.

Yes, I am fairly sure. From cmd:

>>> activate xxx & where snakeviz
~\AppData\Local\Continuum\anaconda3\envs\xxx\Scripts\snakeviz.exe

What is weird is that the exception only seems to be thrown when I run the "xxx" environment via the Atom text editor (via the Hydrogen package to get an ipython console). I run the right environment since, from the ipython prompt:

>>> import sys; print(sys.executable)
~\AppData\Local\Continuum\anaconda3\envs\xxx\python.exe

Is there any way you could replicate this?

I switched the magic to start snakeviz via sys.executable, "-m", "snakeviz", hopefully that'll help with this issue. Commit d4b1632 is in master, so if you install snakeviz from github (e.g. pip install https://github.com/jiffyclub/snakeviz/archive/master.zip) you could give it a go. Thanks for the error report!