JM DR
JM DR

Reputation: 43

Jupyter showing different python versions (python_version vs python --version)

I launched JupyterLab which is using a Python 3 kernel. However, when I am running the following commands below, it is showing different Python versions.

!python -V

Output: Python 2.7.18

from platform import python_version

print(python_version())

Output: '3.6.10'

I am expecting the Python 3.6.10 version to appear as it is the kernel that I launched/that is running. Is there a way to activate the Python 3 version whenever I run the "!python -V" command?

Upvotes: 0

Views: 868

Answers (1)

Nikolay Zakirov
Nikolay Zakirov

Reputation: 1584

The original question is about python kernels so I quickly answer that. Kernels are independent of python that you run you jupyter with.

Try this command: jupyter kernelspec list

You will see your kernels. If you want to have another one here is the doc (https://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for-different-environments) not going deep into that as I can see this is probably not the actual problem.

It seems to me you want to change the interpretor called by "python" command.

You did not specify your OS. So in short:

  1. In MacOs update the symbolic link (How to set Python's default version to 3.x on OS X?)
  2. In Ubuntu use update alternatives (Unable to set default python version to python3 in ubuntu)
  3. In Windows - hmm, haven't use windows in a while so probably here (https://superuser.com/questions/1576758/how-do-i-alias-python3-on-windows)

Upvotes: 1

Related Questions