Install Jupyter Lab and setup a conda environment

Install a kernel in a conda environment for your Data Science Project

Patricia Escalera
3 min readMay 24, 2024
Photo by Irham Setyaki on Unsplash

Are you working on a Data Science project and relying on Google Colab notebooks, where all necessary packages are readily available? While Colab is convenient, having a local development environment on your PC can offer greater flexibility and control. In this article, I’ll guide you through the process of setting up Jupyter Lab on your computer, creating and managing conda environments, and configuring Jupyter Lab to utilize these environments. We’ll also explore the concept of Jupyter kernel and their role within your conda environment.

What is a kernel in Jupyter?

Kernels are programming language specific processes that run independently and interact with the Jupyter Applications and their user interfaces. ipykernel is the reference Jupyter kernel built on top of IPython, providing a powerful environment for interactive computing in Python.

Well, translated to more comprehensible words:

A kernel is the component of Jupyter Lab that runs your code. Think of it like a car’s engine, working under the hood to ensure your code executes correctly. Different kernels can run various types of code, such as Python, Julia, or R. Conda environments help manage these different kernels by creating isolated environments for each, ensuring they operate smoothly and without interference.

These steps are applicable for PCs running Linux Ubuntu, version 20.04 or higher.

Create a conda environment

Create two conda environments, one for our Jupyter Lab and the other for your project packages (ex. pandas, numpy, etc.)

  1. Open a terminal window and download Miniconda, then run the installation script below (ref. Anaconda documentation page)
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh

2. Keep open the terminal window and create a conda development environment where we install Jupyter lab

$ conda create --name newdevenv jupyterlab

Create the 2nd environment for your project with some packages, ex. pandas and numpy

$ conda create --name dataproject-env python pandas numpy

Install ipykernel (python kernel) in your project environment

$ conda activate dataproject-dev
(dataproject-dev) $ conda install ipykernel
(dataproject-dev) $ python -m ipykernel install --user --name dataproject-kernel --display
-name "Python (dataproject env)"

with the — display “Python (dataproject env)” We define how Jupyter Lab will display the environment name.

📚 Resources: How to add conda environment to Jupyter lab

Run Jupyter Lab

$ conda activate newdevenv
(newdevenv) $ jupyter lab

Create a notebook

Click on “Python (dataproject env)” to create a new notebook. This notebook will run in the specified environment, which includes pandas and numpy.

Notebook that runs in dataproject-env environment

You can create as many kernels as you need and easily switch between them. To change the kernel executing your code, simply click on the current kernel name displayed in the upper right corner of your notebook and select a different one from the list.

--

--