0

I know this surely is basic info or knowledge, but I was wondering (and can't find the answer) what is the meaning or what info is displayed just after one executes the python command and starts an Interpreter?

For example, what would this mean in this case?:

Python 3.8.7 (tags/v3.8.7:6503f05, Dec 21 2020, 17:59:51) [MSC v.1928 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>>

I know this is something one sees every time you start an interpreter on the command line, and perhaps something one overlooks, but now it got me wondering.

DarkCygnus
  • 7,420
  • 4
  • 36
  • 59
  • It is showing you the python version information and your computer information – 12944qwerty May 13 '21 at 19:15
  • 2
    It's the version of Python, the github tag, and compilation information. – Barmar May 13 '21 at 19:16
  • @12944qwerty yeah I suspect something like that, but I want to know more specific what is each thing – DarkCygnus May 13 '21 at 19:16
  • @12944qwerty thanks I think the answer over there helps, although the user was asking why 32 when they were on 64, which is not what I'm asking... perhaps document that in this post could be useful – DarkCygnus May 13 '21 at 19:19
  • 1
    @12944qwerty Not really. That question only asks about the `win32` at the end, and the answers don't go into detail about the rest. – Barmar May 13 '21 at 19:19

2 Answers2

4

Let's look at Python's source code to see exactly what it's doing to generate that message. Since if all else fails, you can just look at the source.

If we search for Type "help", "copyright", "credits" or "license()" for more information., one of the results is in Modules/main.c:

#define COPYRIGHT \
    "Type \"help\", \"copyright\", \"credits\" or \"license\" " \
    "for more information."

If we see where this is used, we can see that it's in the pymain_header function - the relevant code is the following:

fprintf(stderr, "Python %s on %s\n", Py_GetVersion(), Py_GetPlatform());
    if (config->site_import) {
        fprintf(stderr, "%s\n", COPYRIGHT);
    }

So, now we need to see what Py_GetVersion() and Py_GetPlatform() do.

Py_GetVersion does the following:

static char version[250];
    PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",
                  PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());
    return version;

So, now we need to see what Py_GetBuildInfo() and Py_GetCompiler() do. PY_VERSION is the version of Python.

The relevant part of Py_GetBuildInfo() is:

PyOS_snprintf(buildinfo, sizeof(buildinfo),
                  "%s%s%s, %.20s, %.9s", gitid, sep, revision,
                  DATE, TIME);

Inferring from the rest of the code, and the build configuration, gitid is either the git tag of the current Python version, or if that doesn't exist, the git branch. sep is just a separator, revision is the short sha-1 hash of the HEAD commit of the python source. I assume DATE and TIME are the date and time of the build.

The source of Py_GetCompiler indicates that it outputs [Clang __clang_version__], [GCC __VERSION__], or [C++] or [C], or something else (such as [MSC] along with the MSC version) depending on what compiled Python.

Lastly, looking at the code for Py_GetPlatform(), it's getting the platform of the current Python build. Possible values seem to include win32, but I'm not sure what the others are, but I assume it refers to the specific Mac and Linux OS versions and such.

So, gathering all this info together, the breakdown is the following:

Python 3.8.7 (tags/v3.8.7:6503f05, Dec 21 2020, 17:59:51) [MSC v.1928 64 bit (AMD64)] on win32

  • Python
  • 3.8.7: Python Version
  • (tags/v3.8.7:6503f05, Dec 21 2020, 17:59:51): (git branch or tag name:git revision short sha-1, build date, build time)
  • [MSC v.1928 64 bit (AMD64)]: [Compiler name and version]
  • on
  • win32: platform name
Random Davis
  • 6,662
  • 4
  • 14
  • 24
  • excellent answer, very thorough and referencing to the source. Thanks :) FWIW in the meantime I continued searching and found this on the [Docs](https://docs.python.org/3/tutorial/interpreter.html#interactive-mode): *"...The interpreter prints a welcome message stating its version number and a copyright notice before printing the first prompt..."* which gives a little bit of info but surely lacking all the detail as this answer has – DarkCygnus May 13 '21 at 20:52
2

Okay, let's look at each part of the message.

  • Python 3.8.7 - The version of python (obviously)
  • tags/v3.8.7:6503f05 - The github tag of the python repo. If you were to go to this tag on github and looked at the latest commit, you'd find the commit ID which is 6503f05
  • Dec 21 2020, 17:59:51 - The release date of this commit. Check the tag again and see that the latest commit was on this date.
  • MSC v.1928 - Microsoft C compiler and version.
  • 64 bit (AMD64) - The 64 bit tells us that this python is 64 bits. See this answer for more explanation on 32 bits and 64 bits.
  • on win32 - The OS information for windows. This is 32-bit windows. I suggest installing the 32 bit python version as the 64 bit python you currently have isn't built for win32.

References:

12944qwerty
  • 2,001
  • 1
  • 10
  • 30
  • Thanks for the answer, quite enlightening. The github part specially interesting – DarkCygnus May 13 '21 at 20:50
  • hey I accepted the other answer just because it was a bit more thorough than this one, but regardless thank you very much for your input :) cheers – DarkCygnus May 13 '21 at 22:26