Hi Paul,

As far as I can tell this is one of the limit of the conda extension
shiped with conda that autolist the kernelspecs. It does not work with
nbconvert.
You need to activate the env and manually install the spec using
`python -m ipykernel install <--options>`, and set the notebook to use
this kernelspec using the notebook UI.
Then, it should work.

Cheers,
-- 
M

On Tue, Feb 7, 2017 at 12:58 PM, Paul Hobson <[email protected]> wrote:
> Hey folks,
>
> I've been searching all morning, but coming up empty. The question is this:
> Is there a way to using the nbconvert python API with a kernel installed in
> a conda environment?
>
>
> Background:
> I'm trying to write a documentation build script for a module that converts
> notebooks to RST, and then compiles HTML docs with Sphinx.
>
> I have installed the module I'm documenting into an isolated conda
> environment called "probscale".
>
> So with this trivial notebook (note the kernelspec):
>
> a_test.ipynb:
> {
>  "cells": [
>   {
>    "cell_type": "code",
>    "execution_count": 1,
>    "metadata": {
>     "collapsed": false
>    },
>    "outputs": [
>     {
>      "name": "stdout",
>      "output_type": "stream",
>      "text": [
>       "[-0.04809765 -0.65510951 -0.06389409 -0.78956431  1.12613107]\n"
>      ]
>     }
>    ],
>    "source": [
>     "import numpy\n",
>     "print(numpy.random.normal(size=5))"
>    ]
>   }
>  ],
>  "metadata": {
>   "anaconda-cloud": {},
>   "kernelspec": {
>    "display_name": "Python [conda env:probscale]",
>    "language": "python",
>    "name": "conda-env-probscale-py"
>   },
>   "language_info": {
>    "codemirror_mode": {
>     "name": "ipython",
>     "version": 3
>    },
>    "file_extension": ".py",
>    "mimetype": "text/x-python",
>    "name": "python",
>    "nbconvert_exporter": "python",
>    "pygments_lexer": "ipython3",
>    "version": "3.5.2"
>   }
>  },
>  "nbformat": 4,
>  "nbformat_minor": 2
> }
>
> When I run:
>
> if 1:
>     import nbformat
>     from nbconvert import preprocessors
>
>     nbfile = 'a_test.ipynb'
>     meta = {
>         'metadata': {
>             'path': '.',
>         }
>
>     }
>     with open(nbfile, 'r') as nbf:
>         nbook = nbformat.read(nbf, as_version=4)
>
>     runner = preprocessors.ExecutePreprocessor()
>     runner.preprocess(nbook, meta)
>
>     with open(nbfile, 'w') as nbf:
>         nbformat.write(nbook, nbf)
>
> I get a KeyError and a NoSuchKernal error
>
> ---------------------------------------------------------------------------
> KeyError                                  Traceback (most recent call last)
> C:\Users\phobson\Miniconda3\envs\probscale\lib\site-packages\jupyter_client\kernelspec.py
> in get_kernel_spec(self, kernel_name)
>     172         try:
> --> 173             resource_dir = d[kernel_name.lower()]
>     174         except KeyError:
>
> KeyError: 'conda-env-probscale-py'
>
> [snip]
>
> C:\Users\phobson\Miniconda3\envs\probscale\lib\site-packages\jupyter_client\kernelspec.py
> in get_kernel_spec(self, kernel_name)
>     173             resource_dir = d[kernel_name.lower()]
>     174         except KeyError:
> --> 175             raise NoSuchKernel(kernel_name)
>     176
>     177         return self._get_kernel_spec_by_name(kernel_name,
> resource_dir)
>
> NoSuchKernel: No such kernel named conda-env-probscale-py
>
>
>
> I tried adding the kernel spec from the notebook to metadata passed to
> runner.preprocess(nbook, meta), but that produced the same result.
>
>
> Any thoughts or guidance would be much appreciated.
>
>
> Cheers,
>
> -Paul
>
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/cbee4894-2f86-44f0-a130-2cf63081e47c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jupyter/CANJQusW2j%2B%3DSGrr%3DodjNEsXgTHwGHHNxQd0LCsksE2K8x4iqTw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to