Python - How do I get version information from code running environment?

To get the python version, you can use the following code:

import platform
platform.python_version()

03%20PM

For libraries, you have to import them and display the value of __version__ module attribute. (works for all libraries that follows PEP 8 style guide)

import pandas, numpy, matplotlib, seaborn
print(pandas.__version__)
print(numpy.__version__)
print(matplotlib.__version__)
print(seaborn.__version__)

46%20PM

2 Likes

Here is possible usage for this. To check that you are running Python 3.x:

import platform
if platform.python_version_tuple()[0] < 3:
    raise Exception("Must be using Python 3")
1 Like