check python version

How to Check Version of Python Modules

Python is a popular programming language that allows you to build powerful applications and websites. Often you may need to check version of your python packages. There are several ways to do this in python. In this article, we will look at different ways to check version of python modules.


How to Check Version of Python Modules

Here are the steps to check python package version.


1. Using PIP

If you have installed pip package installer in your system, you can simply run the following command to check python package details.

$ sudo pip freeze

It will list all python packages along with their versions. If you don’t want to view details of all packages together, you can pass this output to grep command and search for the package of your choice.

Linux
$ sudo pip freeze | grep django
django==2.3

Windows
c:\> pip freeze | findstr django
django==2.3


2. Using version variable

You may also check python package version by importing it in python and calling its __version__ variable.

>>> import django
>>> print django.VERSION
(2,3,0,'final',0)

Depending on your python version, you may need to use .__version__ instead of .VERSION above.

>>> import django
>>> print django.__version__
(2,3,0,'final',0)


3. Using python

You can also execute the above python commands from within terminal as shown below.

$ python -c "import django; print(django.__version__)"
(2,3,0,'final',0)

That’s it. In the above article, we have looked at different ways to get python package version.

Also read:

How to Install Go (Golang) in Ubuntu
How to Extract Substring from String in Bash
How to Split String into Array in Shell Script
How to Check if String Contains Substring in Shell
Shell Script to Remove N Characters from String

Leave a Reply

Your email address will not be published.