As data scientist, I daily work with Jupyter Notebook/ Jupyter Lab. One thing that I used to google a lot every time I start a new project is how to create a new conda environment and add it as Jupyter Kernel.

In this article, I will try to summarize the steps taken to tackle this issue.

✏️ Table of Contents

  • Display all conda envs
  • Create a new conda env
  • Remove a conda env
  • Add conda env as Jupyter Kernel
  • List Jupyter Kernels
  • Delete a Jupyter Kernel
  • Silent Installation of  Python Package
  • Conclusion

Display all conda envs

Simply open your terminal and type the following command:

conda env list

Create a new conda env

To create a new conda environment named 'ex' simply run the following command named:

conda create -n ex #where 'ex' is the name of your new conda environment

This will create a new conda env using the current Python version if you want a specific Python version that is not your current version, then:

conda create -n ex python=3.6

You can validate that the new environment was created by printing all conda envs conda env list.

Remove a conda env

If you finished the project and you now want to delete the conda environment (in that case env named 'ex') simply run the following:

conda env remove -n ex

Add conda env as Jupyter Kernel

This can be done easily by following the below steps:

First activate the env as follow:

conda activate ex

Secondly install the ipykernel:

conda install -c anaconda ipykernel

Finally, for the env ex create the kernel you can define also the Kernel name:

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

You can now deactivate the env conda deactivate env open Jupyter Lab jupyter lab and see the following option:

List Jupyter Kernels

Get a list of available Jupyter Kernels by running:

jupyter kernelspec list

🚀 For people who like video courses and want to kick-start a career in data science today, I highly recommend the below video course from Udacity:

Learn to Become a Data Scientist Online | Udacity | Udacity
Gain real-world data science experience with projects from industry experts. Take the first step to becoming a data scientist. Learn online, with Udacity.

📚 While for book lovers:

Delete a Jupyter Kernel

Delete an available Jupyter Kernels by running:

jupyter kernelspec uninstall ex

and confirm that it was successfully uninstalled by running jupyter kernelspec list while it still exist as a conda env.

🔕 Silent Installation of  Python Package

A nice trick to silently install a conda package is to simply add -y, --yes option in the end.

conda install -c anaconda cx_oracle -y

🤖 Conclusion

This brings us to the end of this article. Hope you got a basic understanding of how create, add and remove a conda environment as Jupyter Kernel.

Thanks for reading, if you liked this article, please consider subscribing to my blog. That way I get to know that my work is valuable to you and also notify you for future articles.‌

💪💪💪💪 As always keep coding, keep creating 🔥🔥🔥🔥