13

I have installed Jupiter notebook and I only have python 2 as a default kernel. I want to change it from python 2 to python 3. How could I do that?Here is the screenshot.

0

5 Answers 5

13
https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-python.html 

Follow the link for managing python. If you use python 2, then install python 3 by using this command.

conda create -n py36 python=3.6 anaconda

After installing python 3, activate python 3 by using this command

activate py36 

Then open jupyter notebook, you will find python on your kernel.

Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't work for me. I can activate my environment, then open python and it is 3.8 (as I want it to be), but when I open jupyter notebook, the only option for a new file is in Python 2.
same here. did you find a way to fix it?
9

You can do this with the following steps:

  1. conda create -n py36 'python=3.6' ipykernel #Replace 3.6 with desired version.

  2. To activate installed jupyter kernal you need run, source activate py36

  3. python -m ipykernel install --user

  4. The interesting part: if you want to switch between kernels (py2-py3) in the same notebook, you need to run, conda install nb_conda

However, if at any point you realize that some of the modules are not available, for that you need to check Anaconda Python version.

python - version

if it is not python 3.x, you need to run

conda create -n py36 python=3.6 anaconda
source active py36

I hope it helps and enjoy switching python versions in the same notebook. You can try to print something in both python2 and python 3.

1 Comment

step 3 was sufficient for me. This is the good answer.
0

You can do this with the following steps:

  1. Create new env by using python3.

    virtualenv -p /usr/bin/python3.7 jupyter_environment

  2. Activate env

    source jupyter_environment/bin/activate

  3. Start jupyter

    jupyter notebook --allow-root

Then open Jupyter notebook, you will find python3 by default on your kernel.

Comments

0

I have succeeded to add Python 3.9 to Jupyter as follows.

# cd /usr/share/jupyter/kernels
# ls
python3
# cp python3 python3.9
# cd python3.9

and changed python3 in the kernel.json file to python3.9:

# cat kernel.json 
{
 "argv": [
  "/usr/bin/python3.9",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3.9",
 "language": "python"

After this, the kernel may be changed through Kernel->Change kernel in Jupyter.

Python 3.9 was installed separately, simply with package manager (zypper in my case).

I think, this should work with Python 2 as well.

Comments

-1

In case you installed the python/jupyter with anaconda, simply update the python from 2.* to 3.*

2 Comments

I have tried all. I have downloaded python 3. Could you explain me the process if you don't mind. I had google it as well.
Please be sure to include more explanation in your answers so that they're useful to future readers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.