easiest way to check python version?

A. Cavallo a.cavallo at mailsnare.com
Wed Jun 10 07:38:47 EDT 2009


A common way to do it is (it is widely accepted):

python -c 'import sys; print sys.version[:3]'

Regards,
Antonio

On Wednesday 10 June 2009 12:25:22 John Machin wrote:
> 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