Python Forum
version/compile info - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: version/compile info (/thread-10119.html)

Pages: 1 2


version/compile info - Skaperen - May-14-2018

when i start up python or python3 with no arguments to get the interactive mode, at first it outputs 2 lines of information and a line of instructions. the 2nd line appears to be compilation information. how can i get all of this information in a python script? i hope the method is the same in both python2 and python3.


RE: version/compile info - wavic - May-14-2018

>>> sys.version
'3.6.4 (default, Jan  5 2018, 02:35:40) \n[GCC 7.2.1 20171224]'



RE: version/compile info - Skaperen - May-14-2018

what did you get as a banner when you started python? is it the same?

Output:
lt1/forums /home/forums 1> python3 Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.version=='[GCC 5.4.0 20160609] on linux' False >>> lt1/forums /home/forums 2> python2 Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.version=='[GCC 5.4.0 20160609] on linux2' False >>> lt1/forums /home/forums 3>
apparently these two versions of Python were compiled on different hosts. i'm assuming that's what "linux" and "linux2" mean (maybe not). if anyone has Python on a different architecture, maybe they can show what they have.


RE: version/compile info - wavic - May-14-2018

(May-14-2018, 05:11 AM)Skaperen Wrote: what did you get as a banner when you started python? is it the same?

Python 3.6.4 (default, Jan 5 2018, 02:35:40)
[GCC 7.2.1 20171224] on linux
Type "help", "copyright", "credits" or "license" for more information.


I would say yes. Without the last line.


RE: version/compile info - DeaD_EyE - May-14-2018

print('Python ' + sys.version)



RE: version/compile info - ljmetzger - May-14-2018

According to the 2nd reference below in Python 3 documentation:
Quote:sys.version
A string containing the version number of the Python interpreter plus additional information on the build number and compiler used. This string is displayed when the interactive interpreter is started. Do not extract version information out of it, rather, use version_info and the functions provided by the platform module.


platform.python_version() Reference: https://docs.python.org/3/library/platform.html?highlight=platform%20python_version#platform.python_version
sys.version Reference: https://docs.python.org/3/library/sys.html?highlight=sys%20version#sys.version
sys.version_info Reference: https://docs.python.org/3/library/sys.html?highlight=sys%20version_info#sys.version_info

The following code works in both Python 2 and Python 3:
import platform
import sys

print("platform.python_version(): {}".format(platform.python_version()))

print("sys.version:               {}".format(sys.version))
print("sys.version_info:          {}".format(sys.version_info))
print("sys.version_info.major:    {}".format(sys.version_info.major))
Output:
platform.python_version(): 2.7.13 sys.version: 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] sys.version_info: sys.version_info(major=2, minor=7, micro=13, releaselevel='final', serial=0) sys.version_info.major: 2
Lewis


RE: version/compile info - ljmetzger - May-14-2018

Quote:Skaperen Wrote:
what did you get as a banner when you started python? is it the same?

Windows 10 - 32 bit Python:
Output:
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
Lewis


RE: version/compile info - Skaperen - May-17-2018

(May-14-2018, 02:39 PM)ljmetzger Wrote:
Quote:Skaperen Wrote:
what did you get as a banner when you started python? is it the same?

Windows 10 - 32 bit Python:
Output:
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
Lewis
does sys.version include "win32" for you?


RE: version/compile info - ljmetzger - May-17-2018

Quote:Skaperen Wrote:
does sys.version include "win32" for you?

64 bit Windows 10 - 32 bit Python
'win32' is returned by sys.platform

import platform
import sys
 
print("platform.python_version(): {}".format(platform.python_version()))
print("platform.platform(): {}".format(platform.platform()))
print("platform.uname(): {}".format(platform.uname()))

print("platform.system(): {}".format(platform.system()))
print("platform.release(): {}".format(platform.release()))
print("platform.version(): {}".format(platform.version()))

system = platform.system()
release = platform.release()
version = platform.version()
print("platform.system_alias(system, release, version): {}".format(platform.system_alias(system, release, version)))
 
print("")
print("sys.platform:              {}".format(sys.platform))
print("sys.version:               {}".format(sys.version))
print("sys.version_info:          {}".format(sys.version_info))
print("sys.version_info.major:    {}".format(sys.version_info.major))
Output:
platform.python_version(): 3.6.5 platform.platform(): Windows-10-10.0.16299-SP0 platform.uname(): uname_result(system='Windows', node='DESKTOP-JGK8FPV', release='10', version='10.0.16299', machine='AMD64', processor='Intel64 Family 6 Model 94 Stepping 3, GenuineIntel')ssor='Intel64 Family 6 Model 94 Stepping 3, GenuineIntel') platform.system(): Windows platform.release(): 10 platform.version(): 10.0.16299 platform.system_alias(system, release, version): ('Windows', '10', '10.0.16299') sys.platform: win32 sys.version: 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] sys.version_info: sys.version_info(major=3, minor=6, micro=5, releaselevel='final', serial=0) sys.version_info.major: 3
Lewis


RE: version/compile info - Skaperen - May-19-2018

so that's where it comes from. what does the "2" mean if python3 does not have it?
Output:
lt1/forums /home/forums 1> py2 Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.platform 'linux2' >>> lt1/forums /home/forums 2> py3 Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.platform 'linux' >>> lt1/forums /home/forums 3>