fccoelho
fccoelho

Reputation: 6204

How to add python 3.6 kernel alongside 3.5 on jupyter

I am trying to test some code on Python 3.6 but my system default python version is python 3.5 I have installed python 3.6 and have tried to follow the jupyter documentation to install a new python kernel

python3.6 -m pip install ipykernel
python3.6 -m ipykernel install --user

But it didn't work since it continues to show a single kernel in the menu: Python3

Has anyone managed to have both 3.5 and 3.6 in the same jupyter installation?

Upvotes: 19

Views: 46682

Answers (7)

user7864386
user7864386

Reputation:

For Windows users:

To add python 3.x ipykernel to jupyter notebook with name "Python 3.x", shown as 'Python 3.x', open your terminal (such as Anaconda Prompt), in base env and enter the following line by line.

For Python 3.10 ipykernel:

conda create -n py310 python=3.10 ipykernel
conda activate py310
python -m ipykernel install --user --name=py310 --display-name "Python 3.10"

For Python 3.7.7 ipykernel:

conda create -n py377 python=3.7.7 ipykernel
conda activate py377
python -m ipykernel install --user --name=py377 --display-name "Python 3.7"

Then close the specific env and go back to the base env, and type in jupyter notebook. Once it opens you'll see the following when you click the "New" drop down menu in the top right corner:

enter image description here

Then to check if the correct Python is installed, open a new notebook and run:

from platform import python_version
print(python_version())

For Python 3.10:

enter image description here

For Python 3.7.7

enter image description here

To remove a specific kernel, you can run the following in your terminal in the base env:

jupyter kernelspec uninstall <kernel name>

Upvotes: 1

Ashish Sondagar
Ashish Sondagar

Reputation: 1095

  • upper solution does not work in my case!!
  • I want to execute code in python3.8 but unfortunately I previous install pytohn3.6
  • I create, activate virtualenv of python3.8 but during lib installation all package installed in virtualenv of python3.6
  • Solution is that I deleted python3.6 env & Setup a new way of Jupyter kernel. After that mine code execute happily & required lib install in virtualenv of python3.8

Upvotes: 1

azeldes
azeldes

Reputation: 303

This is an old question, but like some commenters here I wanted to change the default jupyter completely without using a venv. It seems jupyter keeps this in a json file called kernel.json:

{
 "display_name": "Python 3",
 "language": "python",
 "argv": [
  "/path/to/some/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ]
}

There may be several paths containing this file which are searched in order. To find out what they are on your machine, run:

ipython kernel install --prefix tmp

ipython will throw a warning that the config file is being created in tmp and might not be found, but it will also output the paths it uses to find kernel.json, which you can then edit manually.

Upvotes: 3

Yogesh Awdhut Gadade
Yogesh Awdhut Gadade

Reputation: 2708

Following worked for me:

Commands are executed in Jupyter Notebook (OS: Ubuntu 16.04 LTS)

Upgrade pip:

!pip install --upgrade pip

Install virtual environment:

!pip install virtualenv

Select version of Python you want to use in new environment:

I wanted to create an environment with Python version 3.6 Naming it as Python_3_6:

!virtualenv -p python3.6 Python_3_6

After execution, this will create a folder with the same name in the current working directory (i.e. the location where Jupyter notebook is present)

Create a new option with the name of the created environment

And finally, run the following command:

!python -m ipykernel install --user --name=Python_3_6

This will create a new option with the name Python_3_6 in the menu from where we create a new notebook.

NOTE: One can run above commands from the terminal as well just don't use '!' before the commands.

Upvotes: 3

Lauren
Lauren

Reputation: 5778

one option is to create a kernel that you can use in jupyter notebook. enter image description here

you can do this inside the virtual environment:

  1. Open up your terminal and enter the following line by line

    virtualenv -p python3.6 py_36_env

    source py_36_env/bin/activate

    pip install ipykernel

    python -m ipykernel install --user --name=py_36_env

    jupyter notebook

  2. Then in jupyter notebook you can select the 3.6 environment (py_36_env) from the 'New' drop down menu shown above or from the 'Kernel' drop down menu within a given jupyter notebook.

Upvotes: 31

user3274034
user3274034

Reputation: 153

Steps to install Python 3.6 in Windows

  1. Open command prompt
  2. conda install ipykernel
  3. conda create -n Python3.6Test python=3.6
  4. Activate Python3.6Test
  5. pip install ipykernel
  6. python -m ipykernel install --name Python3.6Test

Here you go with 3.6 C:\ProgramData\jupyter\kernels\Python3.6Test

Now open Jupitor Notebook and see, you will get the Python3.6Test option

Upvotes: 12

Nils Werner
Nils Werner

Reputation: 36765

You should create a virtualenv for each Python version you are using. Create one for Python 3.5:

virtualenv -p /usr/bin/python3.5 py35
source py35/bin/activate
pip install jupyter
jupyter               # Jupyter running Python 3.5
deactivate           # Leave virtualenv

And create one for Python 3.6:

virtualenv -p /usr/bin/python3.6 py36
source py36/bin/activate
pip install jupyter
jupyter               # Jupyter running Python 3.6

Upvotes: 2

Related Questions