Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Version (sys.version) Meaning?

Tags:

python

I've hit what should be a basic question... but my googles are failing me and I need a sanity check.

If I run the following in my Python shell:

>>> import sys
>>> sys.version

from two different Python environments, I get:

'2.7.8 (default, Nov 10 2014, 08:19:18) \n[GCC 4.9.2 20141101 (Red Hat 4.9.2-1)]'

and...

'2.7.8 (default, Apr 15 2015, 09:26:43) \n[GCC 4.9.2 20150212 (Red Hat 4.9.2-6)]'

Does that mean the two environments are actually running slightly different Python guts or is it enough that the '2.7.8' bit in that version string is the same so I can be confident these are 1:1 identical Python interpreters?

If I am guaranteed they are the same, then what's the significance of the date and other parts of that version output string?

like image 428
slumtrimpet Avatar asked Dec 24 '22 00:12

slumtrimpet


1 Answers

All you need to compare is the first bit, the 2.7.8 string.

The differences you see are due to the compiler used to build the binary, and when the binary was built. That shouldn't really make a difference here.

The string is comprised of information you can find in machine-readable form elsewhere; specifically:

  • platform.python_version()

    Returns the Python version as string 'major.minor.patchlevel'.

  • platform.python_build()

    Returns a tuple (buildno, builddate) stating the Python build number and date as strings.

  • platform.python_compiler()

    Returns a string identifying the compiler used for compiling Python.

For your sample strings, what differs is the date the binary was build (second value of the platform.python_build() tuple) and the exact revision of the GCC compiler used (from the platform.python_compiler() string). Only when there are specific problems with the compiler would this matter.

You should normally only care about the Python version information, which is more readily available as the sys.version_info tuple.

like image 166
Martijn Pieters Avatar answered Dec 26 '22 12:12

Martijn Pieters