Home > Enterprise >  Different Python version in jupyter
Different Python version in jupyter

Time:10-20

When I run !python -V, in jupyterlab I have Python 3.8.13

When I run !py -V, also in jupyter I have this time Python 3.10.7

When I run python -V and py -V in Powershell I have Python 3.10.7

When I run

import sys
print(sys.executable)
print(sys.version)
print(sys.version_info)

I have 3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)] sys.version_info(major=3, minor=10, micro=7, releaselevel='final', serial=0)

Could you tell me why the first one is different from the others?

I think it has to be an issue with conda version but I don't know where it comes from.

Thanks

CodePudding user response:

JupyterLab is launched from your Conda environment that has Python 3.8.13 installed in it. This is the actual Python version you are running in jupyterlab, and the same version is shown when you type !python -V.

You also have a separate non-Conda Python 3.10.7 installation on your system. The py command is installed with this Python and is a Python launcher on Windows that works with non-Conda Python installations. The rest of the commands you tried on PowerShell are all outside jupyterlab and use the non-Conda Python version, which is 3.10.7.

CodePudding user response:

You have multiple versions of Python installed to your system, e.g. python -V and py -V use a different one.

The jupyter command starts JupyterLab using one of those Python versions. You can see which one by running import sys and then print(sys.version). If you want to control the Python version used for JupyerLab, then instead of jupyter lab, start it as python -m jupyter lab or py -m jupyter lab. Which one works (either or both) depends on whether JupyterLab is installed for that Python installation.

Similarly, to control the Python version:

  • Use python -m pip ... or py -m pip instead of pip ...

  • Use python -m conda ... or py -m conda instead of conda ...

  • Use python -m jupyter ... or py -m jupyter instead of jupyter ...

  • Related