How do I Get a List of Locally Installed Python Modules?

Python is a high-level programming language that executes the program and returns its output to the console within an instance. It offers the flexibility to install open-source libraries like numpy, pandas, and others to perform particular tasks. Sometimes, if the modules are not pre-installed, the user encounters a “module not found” error in their IDE. In such scenarios, users prefer to pre-install all local Python modules in their directory, which saves time and work efficiency of programmers.

This article is about how users can get a list of locally installed Python modules. 

How to Extract a List of Locally Installed Modules in Python?

Users can extract a list of locally installed Python modules by using the “pip” package manager. For instance, if the user wants to extract useful information from the dataset by performing data exploratory analysis on data. In such scenarios, the user needs to import the “pandas” library in their IDE. Doing so will save the user from an instance raising an “ImportError”, which is a hectic task to resolve and time-consuming too.

To extract a list of locally installed modules in Python, the user can implement the below-listed approaches:

  1. Extracting List of All Installed Modules in Python Using “module()”
  2. Get a List of All Global or locally Installed Python Modules on the “cmd”

Approach 1: Extracting List of All Locally Installed Modules in Python Using “module()”

Having locally installed Python modules gives flexible access to users to utilize their time in working on their program instead of installing the modules from scratch. To get a list of locally installed Python modules, follow the below-listed set of instructions:

Step 1: Launch the IDE 

First, launch the IDE environment according to your preference, in our case, using Jupyter Notebook on Anaconda Navigator. In the “Anaconda Prompt” type “jupyter notebook”. After that, hit the “Enter” key, and the Jupyter Notebook will open in the default browser:

Step 2: Extract the List of Modules Using the “help()” Function

The help() function in Python is utilized to extract information about variables, libraries, or modules by passing the string within the square brackets. For instance, to extract a list of locally installed modules, the help() function will be used as follows:

help('modules')

Approach 2: Get a List of All Global or Locally Installed Python Modules on “cmd” 

To extract a list of all globally or locally installed Python modules on the Command Prompt, the “pip” package manager is necessary to be pre-installed on the system “PATH environment”. Users can install the “pip”, “pip3”, or “conda” package installer from the official web page of PyPi(Python Package Index).

To extract a list of installed Python modules, follow the below-listed straightforward approaches: 

  • Extracting List of All Installed Modules in Python Using “pip freeze” Command 
  • Extracting List of All Installed Modules in Python Using “pip list” Command 

Extracting List of All Installed Modules in Python Using “pip freeze” Command 

Local modules are those that are installed in your system and can be imported to the IDE. To fetch the list of locally installed Python modules, the ‘pip’ should be updated and installed in the system “PATH environment”. To extract a list of locally installed modules in Python using the “pip”, implement the below-listed set of instructions: 

Step 1: Launch the Command Prompt

To launch the Command Prompt, hit the key combinations of “Win+R” and then type “cmd” in the “Open:” field. After that click on the “OK” button:

Step 2: Enter the Command To Fetch the Locally or Globally Installed Python Modules

Get a list of locally or globally installed Python modules, and use the “pip freeze” command. To implement the command on the “cmd” terminal, utilize the below-mentioned command: 

pip freeze

The below-listed snap depicts the information about the locally or globally installed modules in Python using “pip freeze”:

Extracting List of All Installed Modules in Python Using “pip list” Command 

To extract the locally installed Python modules, the “pip” package manager is required. For implementation, follow the below-listed set of instructions:

Step 1: Lunch the “cmd” Terminal

To open the Command Prompt on Windows, follow the key combination of “Win+R” as mentioned in the above section.

Step 2: Enter the “pip list” Command 

To implement a “pip list” command in the terminal, utilize the below-listed command:

pip list

The following snap illustrates information about all the locally installed packages and their versions in Python: 

Note: Another approach to implementing both “pip” commands in the Anaconda IDE, instead of executing them in the “cmd”. To implement the commands, just type the following “pip” commands into the environment:

  • The “pip freeze” command fetches all the locally or globally installed Python modules:
pip freeze
  • The “pip list” is used for getting all the locally installed Python modules:
pip list

Get a List of All the Python Modules That are Outdated

Outdated Python modules may affect the performance and security of the application. In such scenarios, to save the application from vulnerability, there is a need to update the software modules. To get the list of all the installed packages that were outdated, the user can implement the following command in the “cmd”:

pip list --outdated

Upon hitting the “Enter” key, the outdated packages installed on the system will appear, as shown in the below snap:

Get a List of All the Python Modules Which are up-to-date

To perform the task with efficiency particularly working with high-level languages like Python, the user must have the updated version of modules and package manager in their IDE. The user can fetch the list of all the installed modules that are up-to-date in Python. To do so, the user can implement the following command in the “cmd”:

pip list --uptodate

Upon pressing the “Enter” key, the up-to-date packages installed on the system will prompt on the “cmd” console, as shown in the below snap:

BonusTip: How to Install “pip” and Resolve “ModuleNotFoundError” in Python?

To install local modules in Python, the user needs the upgraded version of the “pip”, “pip3”, or “conda” package manager to perform the module installation successfully. However, to install the “pip” package manager on the system directory, the user can download it from an official PyPi web page URL

For a detailed guide on how to install “pip” and fix the “No module named ‘pip’ in Python” error, go through our linked article “Install “pip” on Windows and Linux”.

This article is about fetching the list of locally or globally installed modules in Python.

Conclusion

To get the list of locally installed modules in Python, users can either execute the “help(‘modules’)” in the IDE or go with the “cmd” approach. To extract the modules on the “cmd”, the user can implement two commands. “pipfreeze” to get the locally or globally installed module, and “piplist” to get the list of locally installed modules and version information in Python. This article has demonstrated the approaches to extracting the list of locally or globally installed Python modules.