0

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

2 Answers 2

2

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.

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

1 Comment

Having different situation: !python -V executed inside JupyterLab outputs 3.7.12, while print(sys.executable) returns path to python of version 3.10.14. And I can verify (by looking at version-to-version changes e.g. new argument strict of zip built-in function) that Jupyter running with Python 3.10.14. So in my case sys.executable is accurate, while !python -V isn't.
1

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 ...

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.