Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing Python version in output

Tags:

python

People also ask

How do I print a Python version from Jupyter notebook?

To check the Python version in your Jupyter notebook, first import the python_version function with “ from platform import python_version “. Then call the function python_version() that returns a string with the version number running in your Jupyter notebook such as "3.7. 11" .

What is the current Python version?

Python 3.9. 6, documentation released on 28 June 2021.


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.


import platform
print(platform.python_version())

This prints something like

3.7.2


Try

python --version 

or

python -V

This will return a current python version in terminal.


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'