List Installed Python Modules Linux

Listing Installed Python Modules on Linux

To list the installed Python modules on a Linux system, you can use the following methods:

Method 1: Using pip

You can use the pip package manager to list the installed Python modules. Open a terminal and type:

pip list

This will display a list of all installed Python modules, including their versions.

Method 2: Using pip freeze

Alternatively, you can use the pip freeze command to list the installed Python modules in a format that can be used to reinstall them:

pip freeze

This will display a list of all installed Python modules, including their versions, in the format module==version.

Method 3: Using python -m pip

You can also use the python -m pip command to list the installed Python modules:

python -m pip list

This will display a list of all installed Python modules, including their versions.

Method 4: Using pip show

To get more detailed information about a specific Python module, you can use the pip show command:

pip show module_name

Replace module_name with the name of the module you want to get information about.

Method 5: Using python -c

You can also use the python -c command to list the installed Python modules:

python -c "import pkg_resources; print([d.project_name for d in pkg_resources.working_set])"

This will display a list of all installed Python modules.

Example Output

The output of the above commands will look something like this:

Package          Version
---------------- -------
absl-py          0.15.0
astunparse      1.6.3
cachetools      4.2.4
certifi         2022.6.15

Note: The exact output will depend on the Python modules installed on your system.

Script to List Installed Python Modules

Here is a simple Python script that lists the installed Python modules:

import pkg_resources

def list_installed_modules():
    installed_modules = [d.project_name for d in pkg_resources.working_set]
    print("Installed Python Modules:")
    for module in installed_modules:
        print(module)

if __name__ == "__main__":
    list_installed_modules()

Save this script to a file (e.g., list_modules.py) and run it using Python:

python list_modules.py

This will display a list of all installed Python modules.

Troubleshooting Tips

  • If you encounter any issues while listing installed Python modules, make sure that you have the latest version of pip installed.
  • If you are using a virtual environment, make sure that you have activated it before listing the installed Python modules.
  • If you are using a Linux distribution that uses a package manager other than pip (e.g., apt, yum), you may need to use a different command to list the installed Python modules.