Finding the version of the python package is very easy.
![]()
If you’re wondering how to know the version number of a specific python package, it’s as easy as 1, 2, 3.
I have miniconda with python 3.6.1, conda 4.3.22 & Win 10 64 bit. But the solution that I’m about to provide should work even for those who don’t use conda.
Step 1: Open up your terminal / Console / Command prompt.
Step 2: Type “python”.
Step 3: Import your package and use .__version__ command as follows.
Here, I imported sklearn and used .__version__ property to view it’s version.
That’s it. It must display the version of the package. This technique works for most of the packages.
Thanks for reading! 🙂 If you enjoyed this article, hit that heart button below ❤ Would mean a lot to me and it helps other people see the story.
How to Check Version of Installed Python Modules

One of the most useful features of Python is its huge collection of in-built modules. Modules make everything easier. Due to the availability of numerous python libraries, implementing python code using the in-built modules has increasingly become hassle-free.
But, when we are importing certain modules, we must ensure that they are up-to-date, or else they might raise unwanted errors. In order to write flawless code, we must ensure that the modules are at par with the latest python version in our system.
Checking the version of Python modules
The version of our installed python libraries can be checked and further updated using the pip module. There are many ways in which you can ensure that your system is up to date with the latest release version in order to avoid missing out on exciting new features.
Let us look at how we can check the versions of installed python modules.
Make sure your pip version is >= 1.3! If your pip is not updated, make sure you update it.
If you want to read more about python modules, read this awesome article on Introduction to Python Modules.
Method 1: using pip freeze
The pip freeze method lists all the installed packages and their versions in an alphabetical order.
Open your command prompt and run the following command:
Your output will look something like this:

Pip Freeze
Method 2: Using pip list
The pip list method also works in a similar manner. It will list all the python modules installed in your system followed by their versions that are locally available on your system.
Run the following code to see the entire list of the modules and their versions on your system.

Pip List
Method 3: Using pip show
Using pip show, we can determine the version of one specified module according to our needs. Lets look at how this can be done:
Run the following code in your command prompt: pip show numpy (OR ANY OTHER MODULE VERSION THAT YOU WANNA KNOW)
The output will e something as shown below:
To know more about PIP, check out: Python PIP – Package Manager.
Method 4: using package.__version__ function
This method can be used in the python shell to display the version of a particular library. We can implement this method as follows:
I have used numpy here, you can modify it according to your use. The output would be simply the version of numpy installed in your system.
Method 5: Using importlib from python
There is a python module called importlib(also called ,import library) which can be used to check the version of a particular module in our python script or terminal. The importlib package contains a function called metadata which is useful for extracting information about modules.
Before you use this package, make sure you have it in your system. If not, run pip install importlib in your command prompt in administrator mode as to maintain all PATH properly.
Now, we will look at how to use this package. I will run my code in the python shell.
I already had the DateTime module installed, that’s why I am using it to check the proper functionality of the importlib.metadata.version() . You can use whatever module you want to know the version of.
The output of the above code will be the version of your required module. In this case, 5.0 is the output that I got, because that version of DateTime exists locally.

Using __version__(method 4) followed by importlib(method 5)
Conclusion
In this tutorial, we have seen how to determine the versions of the installed python packages in our system. This can be done in five different ways and each of those methods are extremely easy to use.
The simple syntax of python is one of the biggest reasons why it is so popular. Besides the syntax, the huge collection of in-built functions and modules make programming in this language extremely efficient even at a large scale. Hence, it is important to keep all modules up-to-date so that we can maximize our productivity and make the best use of newly added features!
Как проверить версию модулей на Python?
Когда вы устанавливаете Python, вы также получаете менеджер пакетов Python, pip. Вы можете использовать pip для получения версий модулей Python. Если вы хотите получить список всех установленных модулей Python с номерами их версий, используйте следующую команду:
Вы получите вывод:
Чтобы индивидуально найти номер версии, вы можете использовать grep для этого вывода на машинах * NIX. Например:
В Windows вы можете использовать findstr вместо grep. Например:
Если вы хотите узнать версию модуля в скрипте Python, вы можете использовать атрибут __version__ модуля, чтобы получить его. Обратите внимание, что не все модули поставляются с атрибутом __version__. Например,
How do I check the versions of Python modules?
I installed the Python modules construct and statlib using setuptools :
How do I check their versions from the command line?
![]()
31 Answers 31
With pip, list all installed packages and their versions via:
On most Linux systems, you can pipe this to grep (or findstr on Windows) to find the row for the particular package you’re interested in.
Linux:
Windows:
For an individual module, you can try the __version__ attribute. However, there are modules without it:
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: ‘module’ object has no attribute ‘version‘
Lastly, as the commands in your question are prefixed with sudo , it appears you’re installing to the global python environment. I strongly advise to take look into Python virtual environment managers, for example virtualenvwrapper.
![]()
This is the approach recommended by PEP 396. But that PEP was never accepted and has been deferred. In fact, there appears to be increasing support amongst Python core developers to recommend not including a __version__ attribute, e.g. in Remove importlib_metadata.version..
![]()
![]()
Python >= 3.8:
If you’re on Python >= 3.8, you can use a module from the built-in library for that. To check a package’s version (in this example construct ) run:
Python < 3.8:
Use pkg_resources module distributed with setuptools library. Note that the string that you pass to get_distribution method should correspond to the PyPI entry.
Side notes:
Note that the string that you pass to the get_distribution method should be the package name as registered in PyPI, not the module name that you are trying to import. Unfortunately, these aren’t always the same (e.g. you do pip install memcached , but import memcache ).
If you want to apply this solution from the command line you can do something like:
![]()
Use pip show to find the version!
You can use pip show YOUR_PACKAGE_NAME — which gives you all details of package. This also works in Windows.
grep Version is used in Linux to filter out the version and show it.
![]()
![]()
The better way to do that is:
For the details of a specific package
It details out the package_name, version, author, location, etc.
For more details: >>> pip help
pip should be updated to do this.
On Windows the recommended command is:
![]()
![]()
In Python 3 with brackets around print:
![]()
![]()
module.__version__ is a good first thing to try, but it doesn’t always work.
If you don’t want to shell out, and you’re using pip 8 or 9, you can still use pip.get_installed_distributions() to get versions from within Python:
The solution here works in pip 8 and 9, but in pip 10 the function has been moved from pip.get_installed_distributions to pip._internal.utils.misc.get_installed_distributions to explicitly indicate that it’s not for external use. It’s not a good idea to rely on it if you’re using pip 10+.
![]()
In the Python 3.8 version, there is a new metadata module in the importlib package, which can do that as well.
Here is an example from the documentation:
![]()
The previous answers did not solve my problem, but this code did:
![]()
Use dir() to find out if the module has a __version__ attribute at all.
You can try this:
This will output all the packages with their versions.
![]()
![]()
Some modules don’t have __version__ attribute, so the easiest way is check in the terminal: pip list
If the methods in previous answers do not work, it is worth trying the following in Python:
Note, the .version worked for me on a few others, besides Tornado as well.
![]()
Assuming we are using Jupyter Notebook (if using Terminal, drop the exclamation marks):
if the package (e.g., xgboost) was installed with pip:
if the package (e.g. caffe) was installed with Conda:
![]()
First add executables python and pip to your environment variables. So that you can execute your commands from command prompt. Then simply give Python command.
Then import the package:
Then print the version name
This will definitely work.
![]()
![]()
I suggest opening a Python shell in the terminal (in the Python version you are interested), importing the library, and getting its __version__ attribute.
Note 1: We must regard the Python version. If we have installed different versions of Python, we have to open the terminal in the Python version we are interested in. For example, opening the terminal with Python 3.8 can (surely will) give a different version of a library than opening with Python 3.5 or Python 2.7.
Note 2: We avoid using the print function, because its behavior depends on Python 2 or Python 3. We do not need it, and the terminal will show the value of the expression.