0

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?

3
  • 2
    Doesn't ! invoke system commands? This would mean you query the system python interpreter, which does not have anything to do with the kernel that's currently running. Commented Feb 1, 2022 at 11:15
  • How do you change the active python interpreter? I think this is messing with the script that I am running in the system (developed an sklearn model in Python 3 but active system python interpreter is 2?) Commented Feb 1, 2022 at 11:17
  • You could do !python3 -V, but that still does not guarantee that it's the same interpreter as in the kernel... but at least it's python3. Commented Feb 1, 2022 at 11:17

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

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.