Python Forum
Error while trying to see Python version with "sys.executable"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error while trying to see Python version with "sys.executable"
#1
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.
Reply
#2
import sys

print(sys.version)
print(sys.path)
Reply
#3
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)
>>>
Reply
#4
(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.
Reply
#5
(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
Reply
#6
Thank you very much.

What about "the currently running notebook"?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  run part of a script with a different version of Python jdog 2 395 Jan-09-2024, 08:49 PM
Last Post: jdog
  How to find out from outside Python (in Windows) the current version of Python? pstein 4 680 Oct-04-2023, 10:01 AM
Last Post: snippsat
  How to resolve version conflicts in Python? taeefnajib 0 873 Apr-27-2023, 08:37 PM
Last Post: taeefnajib
  Python venv and PIP version issue JanOlvegg 2 1,199 Feb-22-2023, 02:22 AM
Last Post: JanOlvegg
  Python Version upgrade nitinkukreja 1 855 Feb-04-2023, 10:27 PM
Last Post: Larz60+
  Can't update new python version on Pycharm GOKUUUU 6 3,709 Jul-23-2022, 09:24 PM
Last Post: GOKUUUU
  How to compile a Python script for a Windows / Linux executable? netanelst 2 1,278 May-24-2022, 07:02 AM
Last Post: netanelst
  Building python (3.9.5) with different libexpat version (2.4.6) raghupcr 0 1,261 Feb-25-2022, 11:29 AM
Last Post: raghupcr
  Python keeps running the old version of the code quest 2 3,645 Jan-20-2022, 07:34 AM
Last Post: ThiefOfTime
  Python executable Script (Wrapper) Hwang 2 1,849 Jan-12-2022, 06:53 PM
Last Post: Hwang

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020