How do I find the location of Python module sources?


For a pure python module you can find the location of the source files by looking at the module.__file__. For example,

 >>> import mymodule
>>> mymodule.__file__
C:/Users/Ayush/mymodule.py 

 Many built in modules, however,are written in C, and therefore module.__file__ points to a .so file (there is no module.__file__ on Windows), and therefore, you can't see the source. You can manually go and check the PYTHONPATH variable contents to find the directories from where these built in modules are being imported. 

 Running "python -v"from the command line tells you what is being imported and from where. This is useful if you want to know the location of built in modules.

Updated on: 30-Sep-2019

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements