has2k1 / gnuplot_kernel

A Jupyter/IPython kernel for gnuplot
BSD 3-Clause "New" or "Revised" License
84 stars 25 forks source link

FileNotFoundError during start of the kernel #13

Closed scimax closed 6 years ago

scimax commented 6 years ago

Hi,

I experienced an issue similar to #10, but since the traceback is different the solution to the problem is probably also somewhere else.
I'm running jupyter (lab) on a Windows 10 machine with plain python 3.6 (no distribution like conda). For the installation I tried pip install gnuplot_kernel but since the kernel was not found by jupyter I installed it directly from GitHub, pip install --upgrade --no-cache-dir git+https://github.com/has2k1/gnuplot_kernel.git. At least the kernel is available in jupyter now, but it constantly dies with the Exception FileNotFoundError: [WinError 2] The system cannot find the file specified

The full traceback:

Traceback (most recent call last):
  File "c:\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\python36\lib\site-packages\gnuplot_kernel\__main__.py", line 9, in <module>
    IPKernelApp.launch_instance(kernel_class=GnuplotKernel)
  File "c:\python36\lib\site-packages\traitlets\config\application.py", line 657, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-124>", line 2, in initialize
  File "c:\python36\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "c:\python36\lib\site-packages\ipykernel\kernelapp.py", line 465, in initialize
    self.init_kernel()
  File "c:\python36\lib\site-packages\ipykernel\kernelapp.py", line 376, in init_kernel
    user_ns=self.user_ns,
  File "c:\python36\lib\site-packages\traitlets\config\configurable.py", line 412, in instance
    inst = cls(*args, **kwargs)
  File "c:\python36\lib\site-packages\metakernel\process_metakernel.py", line 54, in __init__
    self.wrapper = self.makeWrapper()
  File "c:\python36\lib\site-packages\gnuplot_kernel\kernel.py", line 237, in makeWrapper
    wrapper = GnuplotREPLWrapper(**d)
  File "c:\python36\lib\site-packages\metakernel\replwrap.py", line 66, in __init__
    encoding="utf-8")
  File "c:\python36\lib\site-packages\metakernel\pexpect.py", line 32, in spawn
    encoding=encoding, codec_errors=codec_errors)
  File "c:\python36\lib\site-packages\pexpect\popen_spawn.py", line 53, in __init__
    self.proc = subprocess.Popen(cmd, **kwargs)
  File "c:\python36\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "c:\python36\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

According to the suggestions in #10 I checked the kernel specs and the kernel.json. The path to python is correct.

import pexpect

pexpect.which('gnuplot')

does not return anything. I alson checked the path variable. The path to gnuplot is in there and it also works on the command line.

System configuration Jupyter 4.4.0 Python 3.6.4 Windows 10

has2k1 commented 6 years ago

does not return anything

That is the problem, and this path issue has only been reported by windows users. Can you try pexpect.which('some-other-executables').

scimax commented 6 years ago

For pexpect.which('notepad.exe') it returns the expected path to the executable. I also tried a few other applications as well. Some work, some don't... strange. But after trying a few applications I realized that sometimes it works only with .exe. And, there it is:

import pexpect

pexpect.which('gnuplot.exe')

Output:

C:\\Program Files\\gnuplot\\bin\\gnuplot.exe
scimax commented 6 years ago

I changed the command parameter in makeWrapper(self) of kernel.py and it seems to work now. But I had to remove the environment variable in front. According to the comment in the line before, the variable is necessary for help commands. So we have to find away around.

The kernel seems to be stable now.

def makeWrapper(self):
        """
        Start gnuplot and return wrapper around the REPL
        """
        if not pexpect.which('gnuplot'):
            raise Exception("gnuplot not found.")

        # We don't want help commands getting stuck,
        # use a non interactive PAGER
        command = 'gnuplot.exe'
        d = dict(cmd_or_spawn=command,
                 prompt_regex=u('\w*> $'),
                 prompt_change_cmd=None)
        wrapper = GnuplotREPLWrapper(**d)
        ...
has2k1 commented 6 years ago

Yes! that line should trip up windows systems.

has2k1 commented 6 years ago

I have not tested the "fix". Just hoping that it should work.

scimax commented 6 years ago

Well, unfortunately not 100%. When I tested it, the kernel didn't die anymore. But when I tried to execute a cell, it kept running infinitely without any output. At that time yesterday, I had no internet connection. Sorry!

But actually it could originate from a different issue. So the original issue of a permanently dying kernel is really solved.

It could not be related to the missing environment variable, can it? I don't know gnuplot very well yet.

scimax commented 6 years ago

Ah, I just saw that you have some handling of the environment variable as well. I will test this as soon as possible!