How to find Python List Installed Modules and Version using pip?

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…

help("modules")

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).

list of Python modules using help function example

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.

pip freeze

or

pip list

Here is an example of listing Python package you have installed on your system using the pip tool.

list of Python modules using pip freeze example

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.

What’s Next?

Check these 39 Most Useful Python Modules holding 95% Python Jobs.

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.

Happy Pythoning!

10 Comments

  1. Good article. Though I am using python for the past many years just for fun on the coding challenges , I did not use much of modules except”math” in few cases. It would be nice if you write an article introducing each module and it’s primary usage.

    1. Hey Sree, Thanks!

      It’s really good idea. I have used many Python modules, some for as per project need and some just to explore. It is not possible to cover all the modules. But I can curate most important and useful modules.

    1. Thanks for putting the point. I have updated the article.

      You can use the command “pip list | wc -l” in terminal. It will work in any of the Linux based systems including Ubuntu.

  2. Thanks Aniruddha , I’m new to python . I was looking for similar kind of help to explore python modules. Suppose I don’t know the module name to import or after importing , how to explore available command and its syntax .. this article given idea. If, possible, please explain bit about modules and how to use it ( VMware, AWS, MS Azure, Windows, Linux related modules).

    1. Hi Abhishek,

      Pip is the standard tool used for all Python management activities. To search a specific module or to know all the commands related to the specific modules, you can use pip command line tool. There are various command provides detail about Python modules. You can find table listing of all such command in this tutorial.

      VMware, AWS, MS Azure, Windows, Linux are the platform where you can install any Python module. So it will not make much difference. Pip provides a common interface for all these platforms. Choose installing Python modules based on the Project requirement.

  3. Thanks for these tricks and commands you shared in this tutorial. This helps me to understand more about Python modules.

Leave a Reply

Your email address will not be published. Required fields are marked *