Find version of python library

Python: Check Package Version

While working with Python you may wonder what is the version of a certain Python package (library) that you are using.

There are several ways of how to get the version of a package or module in Python.

This note describes how to check the version of Python packages from a Python shell, from a command-line (terminal) or using a pip command.

Cool Tip: How to list all the locally installed Python modules and find the paths to their source files! Read More →

Check Version of Python Package

You can get the version of a Python package by running the command as follows directly from a Python shell:

$ python Python 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pkg_resources; print(pkg_resources.get_distribution('selenium').version) - sample output - 4.3.0

To check the Python package version you can also run the above command from a command-line (terminal) as follows:

$ python -c "import pkg_resources; \ print(pkg_resources.get_distribution('selenium').version)" - sample output - 4.3.0

To get the Python package version using a pip , execute:

$ pip show selenium - sample output - Name: selenium Version: 4.3.0 Summary: None Home-page: https://www.selenium.dev Author: None Author-email: None License: Apache 2.0 Location: /projects/myApp/venv/lib/python3.8/site-packages Requires: trio, trio-websocket, urllib3 Required-by:

Cool Tip: How to list dependencies of the installed Python packages! Read More →

Читайте также:  Форма ввода в HTML5

You can also check the Python package version using the pip as follows:

$ pip freeze | grep selenium - sample output - selenium==4.3.0

Источник

How to Easily Find the Version of a Python Library or Module: Step-by-Step Guide

Learn how to find the version of a Python library or module using various methods, including command line and code. Follow our step-by-step guide and ensure smooth programming. Check now!

  • Using __version__ Attribute or .__version__() Method
  • Checking Python Version on the Command Line
  • Using pip show Command
  • Using pip list or pip freeze Command
  • Using pkg_resources.get_distribution(«package_name»).version Command
  • Using Package Manager to List Installed Python Packages
  • Checking Python Version in Linux
  • Other code samples for finding the version of a Python library
  • Conclusion
  • How do I check the version of a Python library?
  • How to see Python version in cmd?
  • How to check installed Python libraries in cmd?
  • How do I check my pip version in Python?

Python is a popular programming language used for web development, scientific computing, data analysis , artificial intelligence, and more. One of the most significant advantages of Python is its vast collection of libraries and modules that developers can use to build powerful applications. However, it’s crucial to know how to find the version of a Python library or module to ensure that you are using the correct version of the library and that your code is compatible with it. In this guide, we will provide a comprehensive step-by-step guide on how to check the version of a Python library or module using various methods, including command line and code.

Using __version__ Attribute or .__version__() Method

Python libraries often have a __version__ attribute or a .__version__() method that can be used to check the library’s version in code. This method is useful when you need to check the version of the library programmatically. Here’s an example code snippet that demonstrates how to use the __version__ attribute to check the version of the pandas library:

import pandas as pd print(pd.__version__) 

Checking Python Version on the Command Line

To check the version of Python installed on your system, use the python or python3 command followed by the —version or -V option in the command line. Here’s an example command that demonstrates how to check the version of python installed on your system:

Using pip show Command

The pip show command can be used to display information about a specific Python library, including the version. This method is useful when you need to find out the version of a library quickly. Here’s an example command that demonstrates how to use the pip show command to check the version of the pandas library:

The pip list command can be used to display a list of all installed Python libraries, including their versions. The pip freeze command can be used to display a list of installed packages, including their version numbers, in a format that can be used to recreate the environment. Here are some example commands that demonstrate how to use the pip list and pip freeze commands to check the version of the pandas library:

pip list pip freeze | grep pandas 

Using pkg_resources.get_distribution(«package_name»).version Command

The pkg_resources module provides a method called get_distribution(«package_name»).version that can be used to check the version of a specific Python library or module in code. This method is useful when you need to check the version of a library programmatically. Here’s an example code snippet that demonstrates how to use the pkg_resources module to check the version of the pandas library:

import pkg_resources print(pkg_resources.get_distribution("pandas").version) 

Using Package Manager to List Installed Python Packages

Various package managers such as Pip, Pipenv, Anaconda Navigator, or Conda can be used to list all installed Python packages on your system. This method is useful when you need to get a list of all installed packages, including their versions. Here’s an example command using Pip:

Checking Python Version in Linux

To check the version of Python installed on a Linux system, use the python -V command in the terminal. Here’s an example command that demonstrates how to check the version of Python installed on a Linux system:

Other code samples for finding the version of a Python library

In Python , for instance, check package version jupyter python

import packagename print(packagename.__version__)

In Python , for instance, how to find the version of python command linw code example

In Shell case in point, how to check version of any library in python code sample

# type below command based on which module version you want to know. $ python -m django --version $ python -m pandas --version

In Python , for instance, how to check current version of library in python code example

#Let's say you want to check tensorflow versionimport tensorflow as tf tf.__version__

In Python , for example, how to know the version of python code example

Step 1: Type Command Prompt on search icon near the windows icon Step 2: On Command Prompt Execute the below command Step 3: python --version

Conclusion

Knowing how to find the version of a Python library or module is crucial for developers working with Python. This guide has provided step-by-step guidance on how to check the version using various methods, including command line and code. By following the outlined methods, developers can easily and quickly check the version of any Python library or module they are using.

Источник

How to Check Version of Installed Python Modules

Checkingversions Of 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:

C:\Users\SHREYA>pip freeze contourpy==1.0.6 cycler==0.11.0 DateTime==5.0 et-xmlfile==1.1.0 fonttools==4.38.0 joblib==1.2.0 kiwisolver==1.4.4 matplotlib==3.6.2 numpy==1.24.1 openpyxl==3.0.10 packaging==23.0 pandas==1.5.2 Pillow==9.4.0 playsound==1.3.0 psutil==5.9.4 pydub==0.25.1 pygame==2.1.3 pyparsing==3.0.9 python-dateutil==2.8.2 pytz==2022.7 scikit-learn==1.2.1 scipy==1.10.0 seaborn==0.12.2 six==1.16.0 threadpoolctl==3.1.0 tk==0.1.0 zope.interface==5.5.2

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:

C:\Users\SHREYA>pip show numpy Name: numpy Version: 1.24.1 Summary: Fundamental package for array computing in Python Home-page: https://www.numpy.org Author: Travis E. Oliphant et al. Author-email: License: BSD-3-Clause Location: C:\Users\SHREYA\AppData\Local\Programs\Python\Python311\Lib\site-packages Requires: Required-by: contourpy, matplotlib, pandas, scikit-learn, scipy, seaborn

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:

import numpy print(numpy.__version__) #displaying version of the numpy

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.

import importlib.metadata print(importlib.metadata.version('DateTime'))

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 And Importlib

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!

Источник

Оцените статью