Computer >> Computer tutorials >  >> Programming >> Python

How to locate a particular module in Python?


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.

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.