Python Forum

Full Version: Error while trying to see Python version with "sys.executable"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone.

I know some computer science concepts and can write programs in Python, which I have done but for my own use in the shell. However, there is a considerable amount of gaps I need to fill before moving forward with my learning.

I've been reading the guide on Installing Packages and tried to see my python version with

In [1]: import sys
        !{sys.executable} --version
But I got an error saying "'C:\Users\<User>' is not recognized as an internal or external command, operable program or batch file." Now, when I do !python --version I get
Output:
Python 3.7.0
I tried to see what path I am getting with sys.executable and is this one

Output:
'C:\\Users\\<User>\\Anaconda3\\pythonw.exe
Is this incorrect?

Actually, I am confused by the following from the documentation:

Quote:It’s recommended to write {sys.executable} rather than plain python in order to ensure that commands are run in the Python installation matching the currently running notebook (which may not be the same Python installation that the python command refers to).

What do they mean by "the currently running notebook"?

An additional question I have regarding this is about the difference between !python --version and sys.version. What I can see is that the former is a command-line command and the latter is an attribute of the sys module, and also that it gives me an installation date and some short info about my system. Is there any advantage or difference I am not seeing?

Thanks in advance.
import sys

print(sys.version)
print(sys.path)
Also, Adding to Axel_Erfurt's post, you can execute:
>>> print(f"Version Info:\n{sys.version_info}")
Version Info:
sys.version_info(major=3, minor=8, micro=1, releaselevel='final', serial=0)
>>>
(Feb-08-2020, 07:57 PM)Axel_Erfurt Wrote: [ -> ]
import sys

print(sys.version)
print(sys.path)

Thank you very much for your reply. I did notice what sys.version outputs, but what is causing the error "'C:\Users\<User>' is not recognized as an internal or external command, operable program or batch file." when I do !{sys.executable} --version? Isn't that supposed to be a correct path, that one in which I have pythonw.exe?

Is there another difference between !python --version and sys.version?

Thanks again.
(Feb-08-2020, 11:28 PM)karkas Wrote: [ -> ]Is there another difference between !python --version and sys.version?

in a Terminal I use

python --version

or

python3 --version

in a Python Script

sys.version
Thank you very much.

What about "the currently running notebook"?