[IPython-dev] Notebooks enforce specific kernel

Thomas Kluyver takowl at gmail.com
Mon Jun 29 13:41:15 EDT 2015


There's two ways you can use kernels with virtualenvs:

1. Don't install kernelspecs, launch the notebook inside virtualenvs when
you want them.
2. Create kernelspecs referring to each virtualenv so you can switch
between them in the notebook interface.

Unfortunately, the two don't mix very well, so as you found, once you've
installed a kernelspec it may end up using that instead of the virtualenv
where you started the notebook.

> 2: It seems notebooks contain a kernel specification of sorts. Does this
mean I can't write a notebook that will run in both Python 2 and Python 3?

If the user only has one Python kernelspec installed, that will be
automatically selected whether the notebook specifies Python 3 or 2. If
they have both, it will prefer the one it was saved with. However, there
isn't currently any way to declare in the metadata that a notebook works
with both, or with only one.

Thomas

On 29 June 2015 at 09:14, Steve Holden <steve at holdenweb.com> wrote:

> Inevitably, almost as soon as I had sent the message I found and deleted
> kernel specs in /usr/local/share/jupyter, which seems to solve the problem
> (as well as explain the message about "attempting to work in a virtual
> environment, as one of the specs was indeed pointing to en executable in a
> virtualenv).
>
> regards
>  Steve
>
> On Jun 29, 2015, at 5:04 PM, Steve Holden <steve at holdenweb.com> wrote:
>
> Since this may be a configuration issue I thought I'd ask on the list
> before filing an issue.
>
> I created a Python2 virtual environment and installed IPython[notebook]
> using pip, plus scipy and some other stuff. I then opened an existing
> notebook, only to find on executing it that it claims scipy isn't installed.
>
> I noticed that the notebook had automatically opened with a Python 3
> kernel, which I found very odd. sys.prefix tells me that it's running
> Python 3 from a completely unconnected virtual environment.
>
> Now I did, once upon a time, attempt to install a Python2 kernel, but my
> configuration control isn't good enough to remind me what I did. I can't
> trace any reference to the "unconnected virtual environment" anywhere in my
> ~/.ipython directory. This raises two questions:
>
> 1: Can anyone tell me where I may have installed this rogue kernel; and
>
> 2: It seems notebooks contain a kernel specification of sorts. Does this
> mean I can't write a notebook that will run in both Python 2 and Python 3?
>
> regards
>  Steve
> --
> Steve Holden steve at holdenweb.com / +1 571 484 6266 / +44 208 289 6308
> / @holdenweb
>
>
>
>
>
>
> --
> Steve Holden steve at holdenweb.com / +1 571 484 6266 / +44 208 289 6308
> / @holdenweb
>
>
>
>
>
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20150629/75a8540a/attachment.html>


More information about the IPython-dev mailing list