JupyterLab launches from base installation even when in conda environment

Question:

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?

Asked By: BaileyA

||

Answers:

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.

Answered By: medium-dimensional
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.