How to find Python List Installed Modules and Version using pip?
Do you want to know all the Python version installed on your system?
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).
HUGE list :O
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.
pip show getopt
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.
pip list | grep getopt
For instance, you can also list out all installed modules with the suffix “re” in the module name.
pip list | grep re
How to count the number of Python modules installed on your system?
You can use
wc (word count) command.
pip list | wc -l
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.