Python: Print Version String from Script

By Xah Lee. Date: . Last updated: .

Print version from the command line:

python --version

Print version from within a script:

#-*- coding: utf-8 -*-
# python

import sys
print sys.version

# 2.7.3 (default, Sep 26 2013, 20:03:06)
# [GCC 4.6.3]

Printing version from script is a important technique to find out which version your script is running. Because, you might have several version installed, and in terminal, there are aliases, links, path environment variables, various shell init scripts, that effect which Python version will start when you type python in shell.

If you have a question, put $5 at patreon and message me.