- How to find Python List Installed Modules and Version using pip?
- 1. Using help() function (without pip):
- 2. Using pip to find Python list installed modules and their Versions:
- How to Check if Python module is installed?
- How to count the number of Python modules installed on your system?
- What is the use of these commands?
- pip list#
- Options#
- Examples#
- List all packages, modules installed in python – pip list
- 1. List all the packages, modules installed in python Using pip list:
- Syntax for pip list command :
- Some Examples of pip list command with options:
- 3. List all the packages, modules installed in python Using pip freeze:
- Author
- Related Posts:
How to find Python List Installed Modules and Version using pip?
Do you want to know all the Python version installed on your system?
I have also recorded a video with a live demo. You can watch or else continue reading.
The main strength of the Python is, the wide range of external libraries are available. As we keep coding in Python, we install many packages. It is easy getting a Python list installed modules on the system. There are a couple of ways you can do that.
Following are the two ways that will work for you to get this list…
1. Using help() function (without pip):
The simplest way is to open a Python console and type the following command…
This will gives you a list of the installed module on the system. This list contains modules and packages that come pre-installed with your Python and all other you have installed explicitly.
Here is an example of running help function on my system (Python version 2).
You don’t need to install any external module to get this list with help() function. But this command does not give you any other information about the package.
If you want to know the version of each installed modules, you can use pip program.
2. Using pip to find Python list installed modules and their Versions:
To find the list of Python packages installed on the system, you can use pip program.
Those who don’t know about pip, it is the best program which is used to install and to manage other Python packages on your system. For more understanding, you can check the complete guide for managing Python modules using pip.
If you have the latest version of Python, pip comes preinstalled with Python.
Run following commands on the command line (not on Python console). You get the complete list of installed Python modules with their versions.
Here is an example of listing Python package you have installed on your system using the pip tool.
Unlike help function, it does not list down preinstalled Python packages.
You can see all the Python packages followed by their version.
Note: Before running this command, ensure if there is a pip installed on your system. For Python version 2.7+ and 3.4+, it comes pre-installed with Python.
The format of the output list of both commands is totally different. Suppose you are using these command in shell scripting. You can choose any of the commands which you find easy for parsing the output package list and get the information.
If you already have parsing code for any of the output from two commands, you can use that command.
Related Read: Why you should learn Shell scripting? (Python vs Shell Scripting)
For more detail about any specific module, run command.
It returns the name of the module/package, version, author, author email, license, location of the installed module and requires.
You can get the author’s email. You can reach out to the author for any specific query related to the Python package.
If you are using python code for commercial purpose, knowing the package’s license is important.
How to Check if Python module is installed?
You can use pip commands with grep command to search for any specific module installed on your system.
For instance, you can also list out all installed modules with the suffix “re” in the module name.
How to count the number of Python modules installed on your system?
You can use wc (word count) command.
Note: grep and wc commands only work with Linux based systems.
What is the use of these commands?
- You can use these commands to list out all the installed modules on your system. Later you can use this list to set up a new identical environment.
- If you face any issue in installed Python package, running these commands make debugging easier.
- Knowing Python module version, you can update the module if a new version of the module is available.
In an upcoming article, I will share, how you can write a Python program to get a list of Python packages and save them in a list.
If you find these commands useful for Python list installed modules, share with your friends. Feel free to write a comment if you have any question regarding handling Python packages.
pip list#
List installed packages, including editables. Packages are listed in a case-insensitive sorted order.
Options#
-o , —outdated # List outdated packages -u , —uptodate # List uptodate packages -e , —editable # List editable projects. -l , —local # If in a virtualenv that has global access, do not list globally-installed packages. —user # Only output packages installed in user-site. —path # Restrict to the specified installation path for listing packages (can be used multiple times). —pre # Include pre-release and development versions. By default, pip only finds stable versions. —format # Select the output format among: columns (default), freeze, or json. The ‘freeze’ format cannot be used with the —outdated option. —not-required # List packages that are not dependencies of installed packages. —exclude-editable # Exclude editable package from output. —include-editable # Include editable package from output. —exclude # Exclude specified package from the output -i , —index-url # Base URL of the Python Package Index (default https://pypi.org/simple). This should point to a repository compliant with PEP 503 (the simple repository API) or a local directory laid out in the same format. —extra-index-url # Extra URLs of package indexes to use in addition to —index-url. Should follow the same rules as —index-url. —no-index # Ignore package index (only looking at —find-links URLs instead). -f , —find-links # If a URL or path to an html file, then parse for links to archives such as sdist (.tar.gz) or wheel (.whl) files. If a local path or file:// URL that’s a directory, then look for archives in the directory listing. Links to VCS project URLs are not supported.
Examples#
$ python -m pip list Package Version ------- ------- docopt 0.6.2 idlex 1.13 jedi 0.9.0
C:\> py -m pip list Package Version ------- ------- docopt 0.6.2 idlex 1.13 jedi 0.9.0
$ python -m pip list --outdated --format columns Package Version Latest Type ---------- ------- ------ ----- retry 0.8.1 0.9.1 wheel setuptools 20.6.7 21.0.0 wheel
C:\> py -m pip list --outdated --format columns Package Version Latest Type ---------- ------- ------ ----- retry 0.8.1 0.9.1 wheel setuptools 20.6.7 21.0.0 wheel
$ python -m pip list --outdated --not-required Package Version Latest Type -------- ------- ------ ----- docutils 0.14 0.17.1 wheel
C:\> py -m pip list --outdated --not-required Package Version Latest Type -------- ------- ------ ----- docutils 0.14 0.17.1 wheel
$ python -m pip list --format=json [, , .
C:\> py -m pip list --format=json [, , .
$ python -m pip list --format=freeze colorama==0.3.7 docopt==0.6.2 idlex==1.13 jedi==0.9.0
C:\> py -m pip list --format=freeze colorama==0.3.7 docopt==0.6.2 idlex==1.13 jedi==0.9.0
When some packages are installed in editable mode, pip list outputs an additional column that shows the directory where the editable project is located (i.e. the directory that contains the pyproject.toml or setup.py file).
$ python -m pip list Package Version Editable project location ---------------- -------- ------------------------------------- pip 21.2.4 pip-test-package 0.1.1 /home/you/.venv/src/pip-test-package setuptools 57.4.0 wheel 0.36.2
C:\> py -m pip list Package Version Editable project location ---------------- -------- ---------------------------------------- pip 21.2.4 pip-test-package 0.1.1 C:\Users\You\.venv\src\pip-test-package setuptools 57.4.0 wheel 0.36.2
The json format outputs an additional editable_project_location field.
$ python -m pip list --format=json | python -m json.tool [ "name": "pip", "version": "21.2.4", >, "name": "pip-test-package", "version": "0.1.1", "editable_project_location": "/home/you/.venv/src/pip-test-package" >, "name": "setuptools", "version": "57.4.0" >, "name": "wheel", "version": "0.36.2" > ]
C:\> py -m pip list --format=json | py -m json.tool [ "name": "pip", "version": "21.2.4", >, "name": "pip-test-package", "version": "0.1.1", "editable_project_location": "C:\Users\You\.venv\src\pip-test-package" >, "name": "setuptools", "version": "57.4.0" >, "name": "wheel", "version": "0.36.2" > ]
Contrary to the freeze command, pip list —format=freeze will not report editable install information, but the version of the package at the time it was installed.
List all packages, modules installed in python – pip list
There are three ways to get the list of all the libraries or packages or modules installed in python using pip list command, pip freeze command and help function .
All the three ways of listing all the packages installed in python are explained below along with we also explained.
- Pip list all the outdated package installed in python
- pip list all the up to date package installed in python
- pip list all installed packages in json format
- pip list installed packages along with package version
1. List all the packages, modules installed in python Using pip list:
open Anaconda prompt and type the following command.
This will get the list of installed packages along with their version in angular braces which is shown below
Syntax for pip list command :
Some Examples of pip list command with options:
c) List all outdated Packages that are not dependencies of other packages.
d) pip list – list all the packages installed using json formatting
f) pip list – python List packages that are not dependencies of installed packages.
g) pip list – python list all package that are upto date.
2. Get the list of all the packages in python Using Help function: To get the list of installed packages in python you can simply type the below command in python IDE
This will list all the modules installed in the system .
3. List all the packages, modules installed in python Using pip freeze:
This will get the list of installed packages along with their version as shown below These are the three different methods that lists the packages or libraries installed in python.
Author
With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark. View all posts