- Is there a way to obtain a list of Python modules available (i.e. installed) on a machine?
This works for me:
help('modules')
- Where is the module code actually stored on my machine?
Usually in /lib/site-packages
in your Python folder. (At least, on Windows.)
You can use sys.path
to find out what directories are searched for modules.
On python command line, first import that module for which you need location.
import module_name
Then type:
print(module_name.__file__)
For example to find out "pygal" location:
import pygal
print(pygal.__file__)
Output:
/anaconda3/lib/python3.7/site-packages/pygal/__init__.py
On Windows machine python modules are located at (system drive and python version may vary):
C:\Users\Administrator\AppData\Local\Programs\Python\Python38\Lib
You can find module code by first listing the modules:
help("modules")
This spits out a list of modules Python can import. At the bottom of this list is a phrase:
Enter any module name to get more help. Or, type "modules spam" to search for modules whose name or summary contain the string "spam".
To find module location:
help("module_Name")
for example:
help("signal")
A lot of information here. Scroll to the bottom to find its location
/usr/lib/python3.5/signal.py
Copy link. To see code, after exiting Python REPL:
nano /usr/lib/python3.5/signal.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With