Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command line execution of a jupyter notebook fails in default Anaconda 4.1. #877

Closed
rtrhd opened this issue Jul 2, 2016 · 3 comments
Closed
Assignees

Comments

@rtrhd
Copy link

rtrhd commented Jul 2, 2016

Command line execution of a jupyter notebook with jupyter nbconvert --to notebook --execute fails after upgrading to Anaconda 4.1.

On saving a jupyter ipython notebook the kernel name is changed from the conventional python2 or python3 to the conda specific form Python [Root] but this is not recognised by nbconvert.

This form is also not recognised when the notebook is opened in the browser in an Anaconda 4.0 installation causing problems sharing notebooks.

The behaviour was observed on OSX/3.5 and Linux/2.7.

Explicit removal of the package nb_conda_kernels resolves the problem, but this package is included by default in Anaconda 4.1.

jupyter nbconvert --to notebook --execute test_python_root.ipynb
[NbConvertApp] Converting notebook test_python_root.ipynb to notebook
[NbConvertApp] Executing notebook with kernel: Python [Root]
Traceback (most recent call last):
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/jupyter_client/kernelspec.py", line 173, in get_kernel_spec
    resource_dir = d[kernel_name.lower()]
KeyError: 'python [root]'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/ron/anaconda3/bin/jupyter-nbconvert", line 6, in <module>
    main()
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/traitlets/config/application.py", line 596, in launch_instance
    app.start()
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/nbconvert/nbconvertapp.py", line 293, in start
    self.convert_notebooks()
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/nbconvert/nbconvertapp.py", line 457, in convert_notebooks
    self.convert_single_notebook(notebook_filename)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/nbconvert/nbconvertapp.py", line 428, in convert_single_notebook
    output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/nbconvert/nbconvertapp.py", line 357, in export_single_notebook
    output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/nbconvert/exporters/exporter.py", line 165, in from_filename
    return self.from_file(f, resources=resources, **kw)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/nbconvert/exporters/exporter.py", line 183, in from_file
    return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/nbconvert/exporters/notebook.py", line 26, in from_notebook_node
    nb_copy, resources = super(NotebookExporter, self).from_notebook_node(nb, resources, **kw)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/nbconvert/exporters/exporter.py", line 130, in from_notebook_node
    nb_copy, resources = self._preprocess(nb_copy, resources)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/nbconvert/exporters/exporter.py", line 302, in _preprocess
    nbc, resc = preprocessor(nbc, resc)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/nbconvert/preprocessors/base.py", line 47, in __call__
    return self.preprocess(nb,resources)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/nbconvert/preprocessors/execute.py", line 141, in preprocess
    cwd=path)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/jupyter_client/manager.py", line 429, in start_new_kernel
    km.start_kernel(**kwargs)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/jupyter_client/manager.py", line 230, in start_kernel
    kernel_cmd = self.format_kernel_cmd(extra_arguments=extra_arguments)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/jupyter_client/manager.py", line 170, in format_kernel_cmd
    cmd = self.kernel_spec.argv + extra_arguments
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/jupyter_client/manager.py", line 82, in kernel_spec
    self._kernel_spec = self.kernel_spec_manager.get_kernel_spec(self.kernel_name)
  File "/Users/ron/anaconda3/lib/python3.5/site-packages/jupyter_client/kernelspec.py", line 175, in get_kernel_spec
    raise NoSuchKernel(kernel_name)
jupyter_client.kernelspec.NoSuchKernel: No such kernel named Python [Root]

@bollwyvl
Copy link

bollwyvl commented Jul 5, 2016

In the near term, the kernel_name (in the current environment) can be specified at the CLI:

jupyter nbconvert Notebook.ipynb --to=html --ExecutePreprocessor.kernel_name=python

Ideally, we'd be able to overload the kernel manager in nbconvert as we have done in the notebook. However, it looks like there is no way to override the kernel discovery of the --execute flag with configuration.

In the case of root, we should likely not append the name... or better still, figure out a less-invasive way to do it.

@ijstokes
Copy link

ijstokes commented Jul 7, 2016

Ack, this is pretty bad. We need to figure out a much better solution to this problem. nbconvert is a thing lots of people do. I'm going to move this to nb_conda_kernel repo where the action will take place (and where the problem originates).

@ijstokes
Copy link

ijstokes commented Jul 7, 2016

This issue was moved to anaconda/nb_conda_kernels#34

@ijstokes ijstokes closed this as completed Jul 7, 2016
drphilmarshall added a commit to tholoien/empiriciSN that referenced this issue Oct 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants