Photo by Markus Spiske on Unsplash
Configure Miniconda So That You Can Choose a Separate Environment Directly From Jupyter Lab/Notebook
To set up Miniconda in such a way that you can see and select all your environments directly in Jupyter Lab/Notebook on Ubuntu, follow these steps:
Step 1: Install Miniconda
Download the Miniconda installer for Linux:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
Install Miniconda:
bash Miniconda3-latest-Linux-x86_64.sh
Follow the instructions, and ensure you initialize Miniconda.
Restart your terminal or run:
source ~/.bashrc
Step 2: Install Jupyter Lab or Notebook
You can install either Jupyter Lab or Jupyter Notebook in the base environment:
conda install jupyterlab # For Jupyter Lab
# or
conda install notebook # For Jupyter Notebook
Step 3: Install ipykernel
in Each Conda Environment
To ensure that each environment is accessible in Jupyter Lab/Notebook, you need to install the ipykernel
package in every environment and register it as a kernel.
Activate your environment:
conda activate myenv
Install
ipykernel
:conda install ipykernel
Add the environment to Jupyter as a kernel:
python -m ipykernel install --user --name=myenv --display-name "Python (myenv)"
Repeat this for all the environments you want to be accessible in Jupyter.
Step 4: Verify in Jupyter Lab/Notebook
Launch Jupyter Lab or Jupyter Notebook:
jupyter lab # For Jupyter Lab # or jupyter notebook # For Jupyter Notebook
When you create a new notebook, you'll be able to select from all the available environments (kernels) under
Kernel
>Change Kernel
.
Step 5: Optionally Install nb_conda_kernels
To make environment management even easier within Jupyter, you can install the nb_conda_kernels
package, which automatically detects all available conda environments.
Install
nb_conda_kernels
in your base environment:conda install nb_conda_kernels
Launch Jupyter, and you'll see all your Conda environments automatically listed under the kernels.
This setup will allow you to see and select separate environments directly within Jupyter Lab or Notebook!