- How to List Installed Python Packages
- List Installed Packages with Pip
- List Packages in a Console with Pip
- List Modules in a Console without Pip
- List Installed Packages with Pipenv
- List Installed Packages with Anaconda Navigator
- List Installed Packages with Conda
- Globally vs Locally Installed Packages
- List Installed Packages with the ActiveState Platform
- modulefinder — Find modules used by a script¶
- Example usage of ModuleFinder ¶
- 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?
- 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?
How to List Installed Python Packages
The Pip, Pipenv, Anaconda Navigator, and Conda Package Managers can all be used to list installed Python packages.
You can also use the ActiveState Platform’s command line interface (CLI), the State Tool to list all installed packages using a simple “state packages” command. For a complete list of all packages and dependencies (including OS-level and transitive dependencies, as well as shared libraries), you can use the Web GUI, which provides a full Bill of Materials view. Give it a try by signing up for a free ActiveState Platform account .
Before getting a list of installed packages, it’s always a good practice to ensure that up-to-date versions of Python, Pip, Anaconda Navigator and Conda are in place.
List Installed Packages with Pip
Both pip list and pip freeze will generate a list of installed packages, just with differently formatted results. Keep in mind that pip list will list ALL installed packages (regardless of how they were installed). while pip freeze will list only everything installed by Pip.
Package Version ---------------------------------- ---------- absl-py 0.7.0
List Packages in a Console with Pip
To list all installed packages from a Python console using pip, you can utilize the following script:
>>> import pkg_resources installed_packages = pkg_resources.working_set installed_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages]) print(installed_packages_list)
['absl-py==0.7.0', 'adodbapi==2.6.0.7', 'alabaster==0.7.12', 'alembic==1.0.7', 'amqp==2.4.1', 'anyjson==0.3.3',
List Modules in a Console without Pip
To list all installed modules from a python console without pip, you can use the following command:
Note that there are some drawbacks to this approach, including:
- If there are a lot of installed packages, this method can take a long time to import each module before it can search that module’s path for sub-modules.
- Modules that have code outside of an if __name__ == “__main__”: code block, and if user input is expected, may cause the code to enter an infinite loop or hang.
List Installed Packages with Pipenv
The pipenv lock -r command can be used to generate output from a pipfile.lock file in a pipenv environment. All packages, including dependencies will be listed in the output. For example:
-i https://pypi.org/simple certifi==2019.11.28 chardet==3.0.4 idna==2.9 requests==2.23.0 urllib3==1.25.8
List Installed Packages with Anaconda Navigator
To list installed packages in an Anaconda environment using Anaconda Navigator, do the following:
- Start the Anaconda Navigator application.
- Select Environments in the left column.
- A dropdown box at the center-top of the GUI should list installed packages. If not, then select Installed in the dropdown menu to list all packages.
List Installed Packages with Conda
The conda list command can be used to list all packages in a conda environment:
# packages in environment at C:\Anaconda2_4.3.1: # _license 1.1 py27_1 alabaster 0.7.9 py27_0
Globally vs Locally Installed Packages
For information about generating a list of installed packages globally vs locally, refer to:
List Installed Packages with the ActiveState Platform
To view a list of installed Python packages in your currently active project using the ActiveState Platform, run the following command on the command line:
The output is a full list of installed packages in your current project:
matplotlib numpy pandas scikit-learn scipy
You can also obtain a complete software bill of materials view of all packages, dependencies, transitives dependencies (ie., dependencies of dependencies), OS-level dependencies and shared libraries (ie., OpenSSL) using the ActiveState Platform’s Web GUI:
The ActiveState Platform automatically builds all Python packages including linked C libraries from source code, and packages them for Windows, Linux and macOS. Because it does it all server-side, there’s no need to maintain local build environments.
modulefinder — Find modules used by a script¶
This module provides a ModuleFinder class that can be used to determine the set of modules imported by a script. modulefinder.py can also be run as a script, giving the filename of a Python script as its argument, after which a report of the imported modules will be printed.
modulefinder. AddPackagePath ( pkg_name , path ) ¶
Record that the package named pkg_name can be found in the specified path.
modulefinder. ReplacePackage ( oldname , newname ) ¶
Allows specifying that the module named oldname is in fact the package named newname.
class modulefinder. ModuleFinder ( path = None , debug = 0 , excludes = [] , replace_paths = [] ) ¶
This class provides run_script() and report() methods to determine the set of modules imported by a script. path can be a list of directories to search for modules; if not specified, sys.path is used. debug sets the debugging level; higher values make the class print debugging messages about what it’s doing. excludes is a list of module names to exclude from the analysis. replace_paths is a list of (oldpath, newpath) tuples that will be replaced in module paths.
Print a report to standard output that lists the modules imported by the script and their paths, as well as modules that are missing or seem to be missing.
Analyze the contents of the pathname file, which must contain Python code.
A dictionary mapping module names to modules. See Example usage of ModuleFinder .
Example usage of ModuleFinder ¶
The script that is going to get analyzed later on (bacon.py):
import re, itertools try: import baconhameggs except ImportError: pass try: import guido.python.ham except ImportError: pass
The script that will output the report of bacon.py:
from modulefinder import ModuleFinder finder = ModuleFinder() finder.run_script('bacon.py') print('Loaded modules:') for name, mod in finder.modules.items(): print('%s: ' % name, end='') print(','.join(list(mod.globalnames.keys())[:3])) print('-'*50) print('Modules not imported:') print('\n'.join(finder.badmodules.keys()))
Sample output (may vary depending on the architecture):
Loaded modules: _types: copyreg: _inverted_registry,_slotnames,__all__ re._compiler: isstring,_sre,_optimize_unicode _sre: re._constants: REPEAT_ONE,makedict,AT_END_LINE sys: re: __module__,finditer,_expand itertools: __main__: re,itertools,baconhameggs re._parser: _PATTERNENDERS,SRE_FLAG_UNICODE array: types: __module__,IntType,TypeType --------------------------------------------------- Modules not imported: guido.python.ham baconhameggs
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
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.