Let’s say you have a Python module somehow installed on a computer, so you can “import” it, and you want to find a path to this module to check its source files.
In this note i am showing how to list all the locally installed Python modules and how to find the paths to these Python modules.
Cool Tip: How to list dependencies of the installed Python packages! Read More →
Python Module Path
To search for the location of the Python modules, firstly start the Python shell:
$ python
- sample output -
Python 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
List all the installed Python modules, by running the help('modules')
command:
>>> help('modules')
- sample output -
Please wait a moment while I gather a list of all available modules...
IPython appdirs h11 retrying
OpenSSL argparse hashlib rlcompleter
__future__ array heapq runpy
_abc ast hmac sched
_ast asttokens html script
...
To get the Python module’s path, execute the commands as follows:
>>> import os.path >>> import <moduleName> >>> print os.path.abspath(<moduleName>.__file__)
For example, to search for the Python pandas
module’s source files location, execute:
>>> import os.path
>>> import pandas
>>> print(os.path.abspath(pandas.__file__))
- sample output -
/home/user/projects/scraper/venv/lib/python3.8/site-packages/pandas/__init__.py
Cool Tip: How to install specific version of a package using pip
! Read More →