Check the versions of Python packages (libraries) | note.nkmk.me (2024)

This article explains how to check the versions of packages (libraries) and modules used in Python scripts, and the versions of packages installed in your environment.

Contents

  • Get package versions in a Python script: __version__
  • Check package versions with pip
    • List installed packages: pip list
    • List installed packages: pip freeze
    • Check details of installed packages: pip show
  • Check package versions with conda: conda list

To check the version of Python itself, refer to the following article.

Get package versions in a Python script: __version__

To get the version of a package used in a Python script, use the __version__ attribute.

The __version__ attribute is recommended by Python Enhancement Proposals (PEP) and is commonly implemented across many packages.

It is important to note that not all packages include the __version__ attribute, as it is not mandatory.

In addition to the __version__ attribute, certain packages, including NumPy and pandas, offer functions and additional attributes for accessing more detailed version information.

Note that the __version__ attribute is not set for the standard library modules such as math and os. These modules do not have individual versions but follow the Python version.

Check package versions with pip

For Python environments managed with pip, you can check information about the installed packages using the following commands. Execute these commands in a command prompt or terminal.

In certain environments, you may need to use pip3 instead of pip. For basic information on how to use pip, such as installing, updating, and uninstalling packages, see the following article.

List installed packages: pip list

pip list displays a list of installed package names and their version numbers.

$ pip listPackage Version------------------ ---------absl-py 0.1.10agate 1.6.0agate-dbf 0.2.0agate-excel 0.2.1agate-sql 0.5.2appnope 0.1.0...

pip list supports the following options:

  • --format <format-name>
    • Sets the display format (columns, freeze, json)
  • -o, --outdated
    • Displays only out-of-date packages
  • -u, --uptodate
    • Displays only up-to-date packages

Refer to the following article for more information.

List installed packages: pip freeze

pip freeze displays a list of installed package names and their version numbers in the freeze format.

$ pip freezeabsl-py==0.1.10agate==1.6.0agate-dbf==0.2.0agate-excel==0.2.1agate-sql==0.5.2appnope==0.1.0...

Unlike pip list --format freeze, pip freeze does not include package management tools such as pip, setuptools, distribute, and wheel by default. These can be included by using the --all option.

Saving the freeze format output to a text file allows for bulk installation of packages at specified versions. Since including package management tools is generally unnecessary for this purpose, they are omitted by default in pip freeze.

Check details of installed packages: pip show

pip show <package-name> displays detailed information about a given package.

It displays detailed information including the version, license, dependent packages, etc.

$ pip show pandasName: pandasVersion: 2.0.1Summary: Powerful data structures for data analysis, time series, and statisticsHome-page: Author: Author-email: The Pandas Development Team <pandas-dev@python.org>License: BSD 3-Clause License...Location: /opt/homebrew/lib/python3.11/site-packagesRequires: numpy, numpy, python-dateutil, pytz, tzdataRequired-by: 

Check package versions with conda: conda list

For Python environments managed with Anaconda, use conda list to view installed packages in the current virtual environment.

When the environment is not activated, use conda list -n <environment-name>.

Check the versions of Python packages (libraries) | note.nkmk.me (2024)

FAQs

How to check versions of Python packages? ›

The simplest option is to use the __version__attribute to check. However, this option will only work if the package has been installed under a specific version number. Use the __version__ attribute to check the Python package/library, __version__ attribute is recommended by PEP (Python Enhancement Proposals).

How do I check my Python libraries? ›

To get a list of installed packages in Python, you can use the pip command-line tool with the list command. This will show all packages installed in the current environment.

How do I identify a Python package? ›

Python Package Check By using importlib Package

util . In this example, we try to import the 'sys' module using importlib. import_module . If the import is successful, it means that Python is installed, and the message “Python is installed.” is printed.

How do I find the version number of a Python module? ›

When a module (or package) includes a version number, the version SHOULD be available in the __version__ attribute. For modules which live inside a namespace package, the module SHOULD include the __version__ attribute. The namespace package itself SHOULD NOT include its own __version__ attribute.

How to check all Python versions installed? ›

Simply press the Windows key and type "Python". The search results will show the installed version, such as "Python 3.7 (32-bit)" or "Python 2.7 (32-bit)".

How do I choose a Python package version? ›

TL;DR: You can install a specific version of a Python package using Pip by running the pip install <package_name>==<version> command. For example, to install version 1.3. 4 of Pandas, execute the pip install pandas==1.3. 4 command from the Terminal.

Where is the Python libraries? ›

Usually the Python library is located in the site-packages folder within the Python install directory, however, if it is not located in the site-packages folder and you are uncertain where it is installed, here is a Python sample to locate Python modules installed on your computer.

How to check the version of a Python package in Jupyter notebook? ›

The easiest ways to determine the Python version running in your Jupyter notebook is to use the built-in sys module. The sys module provides access to some variables used or maintained by the interpreter and functions that interact with the interpreter.

How do I see what's in my Python library? ›

Python gives you several different ways to view package content. The method that most developers use is to work with the dir() function, which tells you about the attributes that the package provides. __builtins__ : Contains a listing of all the built-in attributes that are accessible from the package.

How do I find documentation for Python packages? ›

You can use the doc() function whenever needed to get quick help. However, you have a better way to study the packages and libraries located in the Python path — the Python Package Documentation. This feature often appears as Package Docs in the Python folder on your system. It's also referred to as Pydoc.

How do I see Python package requirements? ›

How To Check For Python Dependencies with Popular Package Managers
  1. Pip Check Command – Check Python Dependencies After Installation. ...
  2. Conda Environment Check – Check Python Dependencies at Installation Time. ...
  3. Poetry Environment Check. ...
  4. Pipdeptree Verification of Installed Python Dependencies.
Aug 7, 2020

How do I find Python package files? ›

A Python installation has a site-packages directory inside the module directory. This directory is where user-installed packages are dropped. A . pth file in this directory is maintained, which contains paths to the directories where the extra packages are installed.

How to check library versions in Python? ›

Methods to Check Version of Installed Python Modules
  1. Method 1: Using pip show command.
  2. Method 2: Using __version__ attribute.
  3. Method 3: Using pip list command.
Aug 2, 2024

How to check which libraries are installed in Python? ›

To check all the installed Python modules, we can use the following two commands with the 'pip': Using 'pip freeze' command. Using 'pip list command.

How do I see available versions of a Python package? ›

Check the versions of Python packages (libraries)
  1. Get package versions in a Python script: __version__
  2. Check package versions with pip. List installed packages: pip list. List installed packages: pip freeze. Check details of installed packages: pip show.
  3. Check package versions with conda : conda list.
Feb 11, 2024

How do I find the version of a Python program? ›

Check Python version on command line and in script
  1. Check the Python version on the command line: --version , -V , -VV.
  2. Check the Python version in a script: sys , platform. Version information as a string: sys.version. Version number as a tuple: sys.version_info. Version number as a string: platform.python_version()
Feb 11, 2024

How to check version of PyPDF2? ›

Use print(PyPDF2.__version__) to tell us which version you're using.

How do I know if I have multiple versions of Python? ›

For example, if you have both Python 3.8 and Python 3.9 installed, you can check the version of Python 3.9 using the command python3. 9 –version. Python version not displayed: If the command python –version does not display the version information, try using the python -V command instead.

How to check pip version? ›

How to check if pip is installed on Windows and Mac: In Command Prompt on Windows or Terminal on Mac, type and enter: pip --version . If pip version is shown then it is installed.

Top Articles
When It All Comes Together: The Beauty of a Great Plan
What is a good Transunion credit score?
9.4: Resonance Lewis Structures
Truist Bank Near Here
Splunk Stats Count By Hour
Shoe Game Lit Svg
Craftsman M230 Lawn Mower Oil Change
What to Do For Dog Upset Stomach
Workday Latech Edu
Undergraduate Programs | Webster Vienna
Ou Class Nav
Walgreens On Nacogdoches And O'connor
Washington, D.C. - Capital, Founding, Monumental
Help with Choosing Parts
Nalley Tartar Sauce
De beste uitvaartdiensten die goede rituele diensten aanbieden voor de laatste rituelen
Watch The Lovely Bones Online Free 123Movies
Wausau Marketplace
Vigoro Mulch Safe For Dogs
Culver's Flavor Of The Day Taylor Dr
Busted News Bowie County
Sef2 Lewis Structure
Naya Padkar Gujarati News Paper
Why Are Fuel Leaks A Problem Aceable
Craig Woolard Net Worth
Criterion Dryer Review
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
Ardie From Something Was Wrong Podcast
Pacman Video Guatemala
Abga Gestation Calculator
Our 10 Best Selfcleaningcatlitterbox in the US - September 2024
Sinfuldeed Leaked
Angel del Villar Net Worth | Wife
Evil Dead Rise - Everything You Need To Know
Shaman's Path Puzzle
Of An Age Showtimes Near Alamo Drafthouse Sloans Lake
The Mad Merchant Wow
Western Gold Gateway
Games R Us Dallas
Property Skipper Bermuda
Taylor University Baseball Roster
Сталь aisi 310s российский аналог
Bob And Jeff's Monticello Fl
Mississippi weather man flees studio during tornado - video
VDJdb in 2019: database extension, new analysis infrastructure and a T-cell receptor motif compendium
How to Install JDownloader 2 on Your Synology NAS
Matt Brickman Wikipedia
Spn 3464 Engine Throttle Actuator 1 Control Command
Houston Primary Care Byron Ga
OSF OnCall Urgent Care treats minor illnesses and injuries
Itsleaa
Latest Posts
Article information

Author: Nathanael Baumbach

Last Updated:

Views: 6611

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Nathanael Baumbach

Birthday: 1998-12-02

Address: Apt. 829 751 Glover View, West Orlando, IN 22436

Phone: +901025288581

Job: Internal IT Coordinator

Hobby: Gunsmithing, Motor sports, Flying, Skiing, Hooping, Lego building, Ice skating

Introduction: My name is Nathanael Baumbach, I am a fantastic, nice, victorious, brave, healthy, cute, glorious person who loves writing and wants to share my knowledge and understanding with you.