How to check for installed modules in Python?

In Python, you can use the `pip` package manager to view installed modules. Here are a few common methods:

Use the command pip list.

Open the command line or terminal window and enter the following command:

pip list

This will list all installed Python modules along with their versions.

2. Command “pip freeze” is used.

Open the command line or terminal window and enter the following command:

pip freeze

This will display all installed Python modules and their versions in text format. The list can be saved to a file for future use.

Use the pkg_resources module in Python code.

In Python code, you can use the `pkg_resources` module to view the installed modules. Here is an example:

import pkg_resources

installed_packages = pkg_resources.working_set

for package in installed_packages:

print(package.key, package.version)

Running the above code will output the installed modules along with their respective versions.

Leave a Reply 0

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


广告
Closing in 10 seconds
bannerAds