2022-04-26

Anaconda (3-2021.11) environment not showing up in Jupyter Notebook

I am having trouble getting my anaconda environment to show up in jupyter notebook. I'm not sure if the current solutions are dated or if I am doing something wrong. I make the behavior clear to hopefully make identifying the issue easier.

I install Anaconda3-2021.11 for Linux from their website:

$ sh ./Downloads/Anaconda3-2021.11-Linux-x86_64.sh
$ reboot
$ conda update conda -y
$ conda install nb_conda_kernels -y

We see the following conda environments:

$ conda env list

# conda environments:
#
base                  *  /home/user/anaconda3

And we can see where python is:

$ echo $CONDA_DEFAULT_ENV

base

$ which python

/home/user/anaconda3/bin/python

$ python --version

Python 3.9.7

I observe the following with jupyter and nb_conda_kernels:

$ jupyter kernelspec list

[ListKernelSpecs] WARNING | Config option `kernel_spec_manager_class` not recognized by `ListKernelSpecs`.
Available kernels:
  python3    /home/user/anaconda3/share/jupyter/kernels/python3

$ python -m nb_conda_kernels list

[ListKernelSpecs] WARNING | Config option `kernel_spec_manager_class` not recognized by `ListKernelSpecs`.
[ListKernelSpecs] [nb_conda_kernels] enabled, 1 kernels found
Available kernels:
  python3          /home/user/anaconda3/share/jupyter/kernels/python3
  conda-root-py    /home/user/anaconda3/share/jupyter/kernels/python3

If I try to create an environment like this:

conda create -n test_env python=3.8

It will show up in conda:

$ conda env list

# conda environments:
#
base                  *  /home/user/anaconda3
test_env                 /home/user/anaconda3/envs/test_env

And we can see where python for test_env is:

$ conda activate test_env
$ echo $CONDA_DEFAULT_ENV

test_env

$ which python

/home/user/anaconda3/envs/test_env/bin/python

$ python --version

Python 3.8.13

But, when in base, jupyter kernelspec list and python -m nb_conda_kernels list outputs do not change.

If I try to do it manually:

$ python -m ipykernel install --user --name test_env --display-name "Python (test_env)"

Installed kernelspec test_env in /home/user/.local/share/jupyter/kernels/test_env

It may show up in the jupyter kernelspec and nb_conda_kernels:

$ jupyter kernelspec list

[ListKernelSpecs] WARNING | Config option `kernel_spec_manager_class` not recognized by `ListKernelSpecs`.
Available kernels:
  test_env    /home/user/.local/share/jupyter/kernels/test_env
  python3     /home/user/anaconda3/share/jupyter/kernels/python3

$ python -m nb_conda_kernels list

[ListKernelSpecs] WARNING | Config option `kernel_spec_manager_class` not recognized by `ListKernelSpecs`.
[ListKernelSpecs] [nb_conda_kernels] enabled, 1 kernels found
Available kernels:
  test_env         /home/deepology/.local/share/jupyter/kernels/test_env
  python3          /home/user/anaconda3/share/jupyter/kernels/python3
  conda-root-py    /home/user/anaconda3/share/jupyter/kernels/python3

But if you actually launch jupyter notebook and create a test_env notebook, then we observe

Notebook Script Input

import sys
print(sys.executable)

Notebook Script Output

/home/user/anaconda3/bin/python
3.9.7 (default, Sep 16 2021, 13:09:58) 
[GCC 7.5.0]

If I reboot nothing changes.

What am I doing wrong?



No comments:

Post a Comment