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"
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
Python 3.7.0
I tried to see what path I am getting with sys.executable and is this one

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

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


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


python3 --version

in a Python Script

Thank you very much.

What about "the currently running notebook"?

Possibly Related Threads…
Thread Author Replies Views Last Post
  db migration(db version control) for python lubaz 2 352 May-30-2021, 01:36 PM
Last Post: lubaz
  Running latest Python version on the Terminal (MAC) Damian 4 578 Mar-22-2021, 07:58 AM
Last Post: Damian
  Optimize a game of life (4 sec for python when 6 ms for C version !) fatango 0 358 Jan-06-2021, 09:13 PM
Last Post: fatango
  Error on Python Version? ErnestTBass 6 873 Dec-09-2020, 04:02 PM
Last Post: ErnestTBass
  Python 3.7, Windows 10, pyinstaller, winsound, no sound in executable kmarien 3 673 Nov-30-2020, 04:10 PM
Last Post: buran
  Last Python (64bit) version for Windows 7? pstein 3 854 Nov-15-2020, 02:09 PM
Last Post: jefsummers
  switch from version 3.5.3 to 3.8.6 get import error python001 9 947 Oct-31-2020, 03:02 PM
Last Post: python001
  Make a Python program executable in Windows Pedroski55 1 579 Sep-26-2020, 12:34 AM
Last Post: bowlofred
  Upgrade Python Version ? JohnnyCoffee 2 801 Aug-08-2020, 09:56 PM
Last Post: Larz60+
  Windows 10 Python Version DevSrc8 6 1,237 Aug-07-2020, 12:36 PM
Last Post: DevSrc8

Forum Jump:

User Panel Messages

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