easiest way to check python version?

John Machin sjmachin at lexicon.net
Wed Jun 10 13:25:22 CEST 2009


On Jun 10, 9:01 pm, dmitrey <dmitrey.kros... at scipy.org> wrote:
> hi all,
> what is easiest way  to check python version (to obtain values like
> 2.4, 2.5, 2.6, 3.0 etc) from Python env?
> I don't mean "python -V" from command prompt.

| >>> import sys
| >>> sys.version
| '2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
(Intel)]'
| >>> sys.version_info
| (2, 6, 2, 'final', 0)
| >>>

"easiest" depends on purpose; e.g. version for display or for logging
exactly what the customer is running. version_info (or a prefix of it)
is the best for things like conditional imports etc

E.g.
py_version = sys.version_info[:2]
if py_version == (2, 3):
    from sets import Set as set

Cheers,
John



More information about the Python-list mailing list