1

How can I have jupyter lab launch JupyterLab from the current conda environment. Is such a thing possible?


Details

I wanted to start experimenting with customizing Jupyter(Lab), and so decided to create a new conda environment for it to contain my experiments. However, launching jupyter lab from this environment still triggers the base environment's installation.

The environment was set up as follows:

conda create --name Jupyter python=3.9
conda activate Jupyter
conda install jupyterlab
jupyter lab

When in the Jupyter conda environment, I can check the versions of installations as follows:

which jupyter
# /Users/baileyandrew/opt/anaconda3/envs/Jupyter/bin/jupyter

which jupyter lab
# /Users/baileyandrew/opt/anaconda3/envs/Jupyter/bin/jupyter

jupyter --version
# Selected Jupyter core packages...
# IPython          : 8.4.0
# ipykernel        : 6.15.2
# ipywidgets       : not installed
# jupyter_client   : 7.3.5
# jupyter_core     : 4.11.1
# jupyter_server   : 1.18.1
# jupyterlab       : 3.4.4
# nbclient         : 0.5.13
# nbconvert        : 6.4.4
# nbformat         : 5.5.0
# notebook         : 6.4.12
# qtconsole        : not installed
# traitlets        : 5.1.1

However, I've noticed that when launching jupyter lab in the terminal, as part of the terminal output it says:

# JupyterLab extension loaded from /Users/baileyandrew/opt/anaconda3/lib/python3.9/site-packages/jupyterlab
# JupyterLab application directory is /Users/baileyandrew/opt/anaconda3/share/jupyter/lab
# Jupyter Server 1.4.1 is running at: [...]

From this I can see that JupyterLab was loaded from my base distribution, as confirmed by the file path (rather than something like "/Users/baileyandrew/opt/anaconda3/envs/Jupyter/bin/jupyterlab"), and further confirmed by the Jupyter Server version of 1.4.1 rather than 1.18.1 as seen in the terminal output from inside the conda environment (posted above).

To further verify that this corresponds to my base installation, I can run the following inside the loaded notebook with the kernel being my base distribution.

!jupyter --version
# Selected Jupyter core packages...
# IPython          : 7.29.0
# ipykernel        : 6.4.1
# ipywidgets       : 7.6.5
# jupyter_client   : 6.1.12
# jupyter_core     : 4.8.1
# jupyter_server   : 1.4.1
# jupyterlab       : 3.2.1
# nbclient         : 0.5.3
# nbconvert        : 6.1.0
# nbformat         : 5.1.3
# notebook         : 6.4.5
# qtconsole        : 5.1.1
# traitlets        : 5.1.0

My question is: how can I have jupyter lab launch JupyterLab from the current conda environment. Is such a thing possible?

BaileyA
  • 145
  • 1
  • 7
  • 1
    According to this [answer](https://stackoverflow.com/a/43197286/7789963), installing `nb_conda_kernels` in the `Jupyter` environment might help launching JupyterLab from `Jupyter`. – medium-dimensional Oct 15 '22 at 17:45
  • 1
    Thanks for the help! It didn't work unfortunately; from what I can tell that will allow me to choose kernels from other environments but doesn't affect the front-end JupyterLab that hosts the kernels. But that's still really useful to me because that's something I had also wanted to know how to do ;) – BaileyA Oct 15 '22 at 17:56
  • 1
    This might sound silly, but can you close the terminal and after (re)launching it, try if JupyterLab is launched with the latest installed version after switching to `Jupyter` environment? – medium-dimensional Oct 15 '22 at 18:02
  • 1
    Not silly at all, that was the solution! If you post it as a formal answer I'll accept it. Thanks so much for your help – BaileyA Oct 15 '22 at 18:08

1 Answers1

1

Please close the terminal, open it and switch to Jupyter environment and launch JupyterLab. This should launch JupyterLab installed in the Jupyter environment.

Relaunching the terminal/shell might be necessary when one wants to use a package P in a non-base environment X installed right after switching from base to X. For more information, please check shell commands open from the wrong location.

medium-dimensional
  • 1,974
  • 10
  • 19