Handle multiple python versions in one jupyter

Overview

Isn't it sometimes?

Specifically

In this situation

bash


$ pyenv versions
  system
  3.6.12
* 3.8.6 (set by /Users/kuryu/.pyenv/version)

Start jupyter with 3.8.6 and aim to run the kernel with 3.6.12.

First put jupyter

bash


$ python -V
Python 3.8.6

$ pip install jupyter

Change python version

bash


$ pyenv global 3.6.12

$ python -V
Python 3.6.12

Create venv if needed

It is possible to build it as it is in the pyenv environment, but this time we will create venv.

bash


$ python -m venv .venv

$ . .venv/bin/activate

(.venv) $ python -V
Python 3.6.12

(.venv) $ pip list
Package    Version
---------- -------
pip        18.1
setuptools 40.6.2
You are using pip version 18.1, however version 20.2.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Insert ipykernel

bash


(.venv) $ pip install ipykernel

(.venv) $ ipython kernel install --user --name=hoge

Leave the virtual environment

bash


(.venv) $ deactivate

Revert python version

bash


$ pyenv global 3.8.6

$ python -V
Python 3.8.6

Start jupyter

bash


$ jupyter notebook

Since the kernel has been added

スクリーンショット 2020-10-22 19.06.29.png

Run and check version

I was able to boot the 3.6.12 kernel in jupyter that booted in 3.8.6.

By the way, I forgot to take a screenshot,

jupyter


sys.executable

If you do something like that, the python path of the venv environment will be displayed properly.

スクリーンショット 2020-10-22 19.01.03.png

When you no longer need the kernel

bash


$ jupyter kernelspec uninstall hoge

It's a story, but be careful not to get confused because it's confusing.

cf.

https://qiita.com/Gattaca/items/80a5d36673ba2b6ef7f0

Recommended Posts

Handle multiple python versions in one jupyter
One liner in Python
Handle markdown in python
Handle Parquet in Python
Multiple graphs are displayed in one window (python)
Multiple regression expressions in Python
Handle Ambient data in Python
Fizzbuzz in Python (in one line)
DMD in Python one dimension
Handle environment variables in Python
Install multiple versions of Python
Avoid multiple loops in Python
Prohibit multiple launches in python
Handle complex numbers in Python
Extract multiple list duplicates in Python
[Python] Show multiple windows in Tkinter
Make python segfault in one line
Handle posix message queues in python
Generate Jupyter notebook ".ipynb" in Python
Handle NetCDF format data in Python
Handle GDS II format in Python
Statistical test (multiple test) in Python: scikit_posthocs
Delete multiple elements in python list
How to handle Japanese in Python
[Python] [3D line graph] Multiple data in one graph, axis values in characters
How to handle multiple versions of CUDA in the same environment
When specifying multiple keys in python sort
CGI server (1) python edition in one line
Memory leak in Python Jupyter Lab (Notebook)?
Send email to multiple recipients in Python (Python 3)
Process multiple lists with for in Python
One liner webServer (with CGI) in python
How to switch python versions in cloud9
Decompose command arguments in one line in Python
[Python] Combine multiple Excel sheets into one
[Python] Invert bool value in one line
Combine multiple python files into one python file
Manage multiple Python versions with update-alternatives (Ubuntu)
Quadtree in Python --2
Python in optimization
CURL in python
One liner that outputs multiplication tables in Python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Try implementing two stacks in one array in Python
Save multiple models in one form with Django
Unittest in python
Connect multiple videos in one shot using OpenCV!
[Python & Unix] Combine multiple PDF files into one.
One liner to 100% CPU1 core usage in Python
Epoch in Python
Get multiple maximum keys in Python dictionary type
Discord in Python
Switch Python versions
Use multiple versions of python environment with pyenv
Sudoku in Python
DCI in Python
quicksort in python