Open a Jupyter Notebook with Python 3

I have both python 2 and python 3 installed on Ubuntu 18.04 LTS:

If I do python -V and python3 -V in my terminal, I get Python 2.7.17 and Python 3.6.9 respectively.

When I open a Jupyter Notebook I only have an option to open a Python 2 notebook. How can I open a python 3 notebook?

When I search for answers, I see solutions that involve installing anaconda - but I already have both Jupyter Notebook and Python 3 on my machine. I don't want to mess things up by installing further versions of python and Jupyter Notebook if I don't need to. Is this best way to do this via anaconda?


Solution 1:

python as such is not a command. It is link to a version of python either 2.x or 3.x. In your case, it is pointing to python 2.x

so when you installed ipykernel using python -m ipykernel install --user or python -m pip install ipykernel it installed as python2.x.

to fix this, you can install ipykernel as pythion3. Just replace python with python3. so your command will be

python3 -m pip install ipykernel

Now run jupyter and check if you can see the python3.x kernel.

On a separate note, if you really don't want to mess your system with multiple version of pythons, docker images would be your best bet. It takes away all complexity of installing python and other tools.