question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Broken jupyter notebook kernel integration with conda environments

See original GitHub issue

Greetings. I’m currently in a Jupyter kernel hell. I can’t figure how to fix it. And I’m not sure whether it’s a Jupyter or conda issue, so thanks for the patience!

Here’s my setup. I use conda to manage my python environments. I work on many different projects that use Jupyter notebooks, each project having its own environment (specified in environment.yml files).

I recently reinstalled conda to update my root environment to Python 3.6 and conda 4.3.13. As part of this reinstallation, I tried to remove files that I thought would get freshly regenerated including jupyter configuration files (IIRC).

This reinstallation of conda triggered the issue:

  • when I run jupyter notebook with the conda environment activated, the specific conda environment is not available in the spawned notebook browser.
  • If I run python -m ipykernel.kernelspec (I think) then I the activated conda environment becomes the default Python 3 kernel for all my notebook servers.
  • Creating new conda environments with jupyter installed does not add them to the list of kernels in jupyter.

Before I reinstalled conda (and deleted jupyter config directories since I wanted to freshly reinstall everything related to python):

  • if I launched a notebook from an activated conda environment, the default Python 3 kernel would correspond to that notebook
  • if I created a new conda environment, the kernel would show up as a choice in all jupyter sessions regardless of which environment jupyter notebook was running from
  • I never had to mess around with configuration files.

So I think I’ve broken something and I want the old (or any environment aware) behavior back. Tagging @minrk @jakevdp @kalefranz @asmeurer in case you or someone you mention can help. Will really appreciate any guidance!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:15
  • Comments:25 (2 by maintainers)

github_iconTop GitHub Comments

100reactions
dhimmelcommented, Mar 16, 2017

conda install nb_conda_kernels failed with:

UnsatisfiableError: The following specifications were found to be in conflict:
  - nb_conda_kernels -> _nb_ext_conf -> nb_anacondacloud -> python 2.7* -> openssl 1.0.1*
  - python 3.6*

So I installed nb_conda_kernels from conda-forge using:

conda install --channel=conda-forge nb_conda_kernels

Now I can choose from my conda environments in the Jupyter kernel menu. Phew!

Note that the nb_conda_kernels README states:

To use a conda environment as a kernel, don’t forget to install ipykernel in this environment or it won’t show up in the kernel list.

21reactions
dhimmelcommented, Mar 16, 2017

I think Continuum stopped shipping their environments-as-kernels plugin by default - you can probably still install it

@takluyver, thanks for that info! It was enough for me to track down nb_conda_kernels (anaconda cloud, repo). Once I’m back at the affected machine, I’ll let you know if this fixes my issues.

nb_conda also looks interesting (allows you to manage conda environments in a Jupyter browser tab).

In worst case, I should be able to use the single kernel installation commands you link to:

source activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
source activate other-env
python -m ipykernel install --user --name other-env --display-name "Python (other-env)"

But I’m not a huge fan of this solution as it’s a manual step. Furthermore, when we have several people collaborating on a repo, we want them to all have the same kernel names for conda environments.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conda environments not showing up in Jupyter Notebook
I looked at this question: Link Conda environment with Jupyter Notebook But there isn't such a directory as ~/Library/Jupyter/kernels on my computer!
Read more >
Primal Data Advent Calendar #2: How to fix Conda ... - Medium
Launch JupyterLab, e.g. by running jupyter lab from a terminal (or jupyter notebook if you don't have JupyterLab yet); See all the Conda...
Read more >
Adding An Environment to Jupyter Notebooks - E. Chris Lynch
Step 1: Create your environment. Using conda in your terminal, type: · Step 2: Activate your environment. In the terminal: · Step 3:...
Read more >
Get Your Conda Environment to Show in Jupyter Notebooks
1. First, install nb_conda_kernels in your base environment. Once this is installed any notebook running from the base environment will ...
Read more >
Conda, Jupyter and Emacs - malb::blog - WordPress.com
One solution is EIN, the Emacs IPython Notebook. ... inside your conda environment will install a kernel of the same name, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found