Installed Python Modules List करना
Locally Installed Python Modules की List प्राप्त करने के कई तरीके हैं।
तरीका 1: Python Shell में help() का उपयोग
>>> help('modules')
Please wait a moment while I gather a list of all available modules...
BaseHTTPServer brain_nose markupbase stat
Bastion brain_numpy marshal statvfs
CGIHTTPServer brain_pkg_resources math string
Canvas brain_pytest matplotlib stringold
...
तरीका 2: Terminal में pip freeze का उपयोग (अनुशंसित)
$ pip freeze asn1crypto==0.22.0 astroid==1.5.2 attrs==16.3.0 Automat==0.5.0 backports.functools-lru-cache==1.3 cffi==1.10.0 ...
यह Format requirements.txt के लिए Perfect है।
तरीका 3: pip list का उपयोग (pip >= 1.3)
$ pip list asn1crypto (0.22.0) astroid (1.5.2) attrs (16.3.0) Automat (0.5.0) backports.functools-lru-cache (1.3) ...
तरीका 4: Python Code से Programmatically
import pkg_resources
installed_packages = pkg_resources.working_set
installed_packages_list = sorted([f"{i.key}=={i.version}" for i in installed_packages])
print(installed_packages_list)
तरीका 5: importlib.metadata (Python 3.8+)
import importlib.metadata
packages = importlib.metadata.distributions()
for pkg in packages:
print(f"{pkg.metadata['Name']}=={pkg.version}")
Comparison:
| Method | Use Case |
|---|---|
pip freeze |
Requirements.txt Generate करना |
pip list |
Human-Readable List |
help('modules') |
Interactive Exploration |
pkg_resources |
Programmatic Access (Legacy) |
importlib.metadata |
Programmatic Access (Modern) |