This post will introduce you useful ways to check what version of Python is running.
- Python’s version can be check on the command line with
- Python’s version can be check in script with
Check version on the command line
Commands below can be used if both Python 2 and 3 are installed on your system and the default running one is Python 2.
python --version prints out the current running version.
python --version >> Python 2.7.17 python -V >> Python 2.7.17 python3 --version >> Python 3.6.9 python3 -V >> Python 3.6.9
Check version in script
platform module 2 default libraries which can be used to get the version of Python that is actually running.
They are used in the situation where you don’t know which Python are powering your app. So you need to add a version check in the app’s script to make sure.
import sys import platform print(sys.version) >> 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] print(sys.version_info) >> sys.version_info(major=3, minor=6, micro=9, releaselevel='final', serial=0) print(platform.python_version()) >> 3.6.9 print(platform.python_version_tuple()) >> ('3', '6', '9')