How can I print the version number of the current Python installation from my script?
2021-01-13
Printing Python version in output
The Question :
496 people think this question is useful
The Question Comments :
The Answer 1
620 people think this answer is useful
Try
import sys print(sys.version)
This prints the full version information string. If you only want the python version number, then Bastien Léonard’s solution is the best. You might want to examine the full string and see if you need it or portions of it.
The Answer 2
209 people think this answer is useful
import platform print(platform.python_version())
This prints something like
3.7.2
The Answer 3
62 people think this answer is useful
Try
python --version
or
python -V
This will return a current python version in terminal.
The Answer 4
34 people think this answer is useful
import sys
expanded version
sys.version_info sys.version_info(major=3, minor=2, micro=2, releaselevel='final', serial=0)
specific
maj_ver = sys.version_info.major repr(maj_ver) '3'
or
print(sys.version_info.major) '3'
or
version = ".".join(map(str, sys.version_info[:3])) print(version) '3.2.2'
The Answer 5
7 people think this answer is useful
If you are using jupyter notebook Try:
!python --version
If you are using terminal Try:
python --version