0

Previously when I launched a jupyter-notebook within a conda environment I would have access to the conda environment. I recently started with a clean Anaconda3 (macOS) install and now I can no longer connect to the conda env with jupyter. The issue seems to be related to this issue and this stack-overflow question.

As noted in the comments the question is closely related to this SO question as well. However question is probably closer and none of the answers in either fix my issue.

I would expect after creating and activating a conda env, that either jupyter notebook:

  • would work out of the box and recognize the environment it was launched in: this does not happen. the jupyter-notebook doesn't have access to the modules installed in the new env
  • or, i would need to run conda install jupyter in the new environment. the install fails with ImportError: cannot import name 'ensure_dir_exists'. Note the traceback does indeed indicate that it is using the correct conda-env /Users/brook/anaconda3/envs/test2/lib/python3.6/site-packages/notebook/nbextensions.py

I tried the following:

  • conda update jupyter_core jupyter_client in the base env: this did not fix any of the problems
  • conda install jupyter_core jupyter_client notebook in the new env: these installed correctly but then when i ran jupyter notebook i got ImportError: cannot import name 'ensure_dir_exists'
  • conda install nb_conda in the new env but that also failed with ImportError: cannot import name 'ensure_dir_exists'
  • conda install nb_conda in the base env: this almost worked - i think. after launching the notebook the conda tab shows my current env as the default.

enter image description here

However when creating a notebook i do not see it listed as an option

enter image description here

I thought that since its checked as the default the "Python 3" option would be the current env "test3". However this still didn't work - importing modules give ModuleNotFoundError and double checking at the command line the modules are correctly installed.

Finally. I should note that recently I did a Unix install on a cloud instance and running conda install jupyter in the new env worked as expected.

For those who made it this far, some details:

  • macOS (10.11.6)
  • i tried the graphical-installer, also the cmd line install from the most recent version as well as 5.3.1 and 5.2.0
  • and ...

enter image description here

Thanks!

brook
  • 247
  • 2
  • 15
  • Possible duplicate of [Conda environments not showing up in Jupyter Notebook](https://stackoverflow.com/questions/39604271/conda-environments-not-showing-up-in-jupyter-notebook). Note, there was a change in Conda that now requires `nb_conda_kernels` installed in the **base** env and `ipykernel` installed in other envs you wish to use in Jupyter. – merv Mar 02 '19 at 20:26
  • @merv Yes thats close. Thanks. There were a few others too but the question closest to mine in terms of errors thrown is the SO question I listed above. Sadly installing `ipykernel` does not fix anything. it installs without error, but then `jupyter notebook` gives `Error executing Jupyter command 'notebook': [Errno 2] No such file or directory`. installing notebook then works, but then executing `jupyter notebook` gives the `ImportError: cannot import name 'ensure_dir_exists'` error again. Note: I re-ran a Unix install without any issues so I'm guessing this is mac-specific. – brook Mar 03 '19 at 05:03
  • I just noticed that you're trying to launch Jupyter from within the env you want to use. That's not how I use it. I only have Jupyter installed in **base** and I only run `jupyter notebook` from there. Then, all other envs with `ipykernel` are available in Jupyter. – merv Mar 03 '19 at 19:43
  • @merv - I've tried launching from both the base env and the new one. I'm realizing the SO-question you referenced in your initial comment, wasn't specific to my original question but did address the issue that showed up for me after I installed `nb_conda`. After installing `ipykernel` I do now see the conda env listed when creating a notebook. Sadly however there is a new error - the notebook kernel dies with `ImportError: cannot import name 'create_prompt_application'` – brook Mar 03 '19 at 20:14

0 Answers0