Add more kernels with Jupyter Notebook

Introduction

This is an introduction of how to handle multiple virtual environments when using Python with Jupyter Notebook.

Add a virtual environment for the kernel

In the following, we will add a Python 3.8 virtual environment as a sample. Let's say Python3.8 can be run with the python3.8 command. If not installed, Download and install it from https://www.python.org/downloads/ etc.

First, create a virtual environment called venv38 and activate it. If you want to use a different virtual environment name, read venv38 below as appropriate.

python3.8 -m venv venv38
source venv38/bin/activate

Install the required libraries appropriately with pip install ....

Add a virtual environment to the kernel.

pip install ipykernel
python -m ipykernel install --name venv38

Use of added kernel

Let's use jupyter in a non-virtual environment. Once, exit the virtual environment with deactivate.

Start Jupyter Notebook with jupyter-notebook. If you select "venv38" from "New" on the upper right, you can start anew in the virtual environment of venv38.

Modify the kernel of an existing notebook

First, open your existing notebook. You can change the kernel with Change kernel in the Kernel menu of Jupyter Notebook. If you can change it, the kernel display on the upper right will change.

Confirmation of added kernel

In the following, it will be executed on the added virtual environment.

You can see a list of kernels and their paths with jupyter kernelspec list.

Delete the added virtual environment

You can remove the added virtual environment with jupyter kernelspec uninstall venv38.

Add library

In the following, it will be executed on the Jupyter Notebook of the added virtual environment.

For example, let's say you want to add a NumPy installation to venv38. Normally, you can do it with ! Pip install numpy, but this will install it on your console instead of venv38. If you want to install from Jupyter Notebook to virtual environment, do as follows. The path is not the path confirmed above, but the path of the virtual environment created first.

!source /path/to/venv38/bin/activate; pip install numpy

that's all

Recommended Posts

Add more kernels with Jupyter Notebook
Using Graphviz with Jupyter Notebook
Use pip with Jupyter Notebook
Play with Jupyter Notebook (IPython Notebook)
Allow external connections with jupyter notebook
Formatting with autopep8 on Jupyter notebook
Visualize decision trees with jupyter notebook
Make a sound with Jupyter notebook
Use markdown with jupyter notebook (with shortcut)
Convenient analysis with Pandas + Jupyter notebook
The usual way to add a Kernel with Jupyter Notebook
Use nb extensions with Anaconda's Jupyter notebook
Use apache Spark with jupyter notebook (IPython notebook)
I want to blog with Jupyter Notebook
Use Jupyter Lab and Jupyter Notebook with EC2
Try SVM with scikit-learn on Jupyter Notebook
How to use jupyter notebook with ABCI
Linking python and JavaScript with jupyter notebook
[Jupyter Notebook memo] Display kanji with matplotlib
Rich cell output with Jupyter Notebook (IPython)
Jupyter Notebook memo
Introducing Jupyter Notebook
Powerful Jupyter Notebook
Jupyter notebook password
Jupyter Notebook memo
How to debug with Jupyter or iPython Notebook
Analytical environment construction with Docker (jupyter notebook + PostgreSQL)
Data analysis for improving POG 2 ~ Analysis with jupyter notebook ~
Verify NLC accuracy with Watson Studio's Jupyter Notebook
Try using conda virtual environment with Jupyter Notebook
Fill the browser with the width of Jupyter Notebook
Graph drawing with jupyter (ipython notebook) + matplotlib + vagrant
Add / remove kernel to use jupyter with venv
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
Multiple selections with Jupyter
Candlestick with plotly + Jupyter
Easy Machine Learning with AutoAI (Part 4) Jupyter Notebook Edition
Get started Jupyter Notebook
Monitor the training model with TensorBord on Jupyter Notebook
Drawing a tree structure with D3.js in Jupyter Notebook
Import specific cells from other notebooks with Jupyter notebook
EC2 provisioning with Vagrant + Jupyter (IPython Notebook) on Docker
3 Jupyter notebook (Python) tricks
Use nim with Jupyter
[Cloud103] # 3 Jupyter Notebook again
Machine learning with Jupyter Notebook in OCI Always Free environment (2019/12/17)
Reflect the virtual environment created with Miniconda in Jupyter notebook
Day 65 (Solution) Jupyter notebook does not work with Kernel Not Conected.
I want to use a virtual environment with jupyter notebook!
Connect the Jupyter Notebook kernel to Spyder with Jupytext enabled
Write charts in real time with Matplotlib on Jupyter notebook
Try clustering with a mixed Gaussian model on a Jupyter Notebook
Shortcut key for Jupyter notebook
Parallel computing with iPython notebook
Introduced Jupyter Notebook to CentOS 7
Display HTML in Jupyter notebook
Multiprocessing error in Jupyter Notebook
Try using Jupyter Notebook dynamically
[Super Basics] About jupyter Notebook
View PDF on Jupyter Notebook
homebrew, pyenv, anaconda, Jupyter Notebook