[PYTHON] Settings for easy selection of multiple kernels in Jupyter

Introduction

Recently, I started to create a virtual environment in Anaconda and code it in an environment that suits my purpose. Among them, for some reason only one of the PCs I own was able to select the kernel from Jupyter Notebook without any settings, but on other PCs I select the kernel without settings. I couldn't. (Probably a problem with the version of Anaconda.) So, I did a lot of research on the net so that I could select the kernel from Jupyter Notebook. However, in my environment (because it is Windows), including Additional packages did not work, or the command information was out of date, so I used it for myself. I will summarize it in. With this setting, you can change the kernel in an instant as follows! jupyter_disp.png

Execution environment

Setup steps

Creating a virtual environment

You can easily create a virtual environment by using conda. This time, it is assumed that jupyter will be used, so install jupyter at the same time when creating this virtual environment.

create_env


#Create virtual environment, install jupyter
$ conda create --name=test python=python3.6 jupyter
#Check if the virtual environment is created, if it is displayed in the list, it is successful
$ conda info -e

Enter the appropriate python version and --name = according to your environment.

Add virtual environment kernel to jupyter

At this stage, I don't think the kernel has been added yet. Now try running the following command:

check_kernel


#View available kernels
$ jupyter kernelspec list

Add the kernel of the virtual environment you added earlier here. Execute the following command with the virtual environment activated.

install_kernel


#Activate virtual environment
$ activate test
#Add kernel
$ ipython kernel install --user --name=test --display-name=test

Now you can switch and select kernels on Jupyter Notebook.

Finally, I will summarize the main options when adding a kernel.

option role
-h, --help Get help on options
--user Installed for currently logged in user
--name NAME Specify the name of the kernel spec
When specifying multiple IPython kernelsMandatory
--display-name DISPLAY_NAME Specify the name of the displayed kernel

How to remove the added kernel

The added kernel information is located in ~ \ AppData \ Roaming \ jupyter \ kernels with the --user option. You can remove the added kernel by deleting the folder with the name specified by --name here.

You can also remove the kernel with the following command.

uninstall_kernel


#Remove kernel
$ jupyter kernelspec uninstall test

reference

  1. stack overflow - Using both Python 2.x and Python 3.x in IPython Notebook
  2. Coexistence of Anaconda 2 and Anaconda 3 in Jupyter + Bonus (Julia)
  3. Easy way to switch virtual environment created by Conda on Jupyter

Recommended Posts

Settings for easy selection of multiple kernels in Jupyter
Easy setting of Firewalld in multi-zone
Snippet settings for python jupyter notebook
Handle multiple python versions in one jupyter
Jupyter Notebook extension, nbextensions settings for myself
Process multiple lists with for in Python
How to make multiple kernels selectable on Jupyter
Browser specification of Jupyter Notebook in Windows environment
Examine any combination of values in multiple arrays
Logging settings for daily log rotation in python
A proposal for versioning of features in Kedro
Easy understanding of Python for & arrays (for super beginners)
Format one line of json for easy viewing
Coexistence of Anaconda 2 and Anaconda 3 in Jupyter + Bonus (Julia)
Settings for Python coding in Visual Studio Code
Basic story of inheritance in Python (for beginners)
Settings for getting started with MongoDB in python