Open In App

Get Location of Python site-packages Directory

Last Updated : 09 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

A Python installation has a site-packages directory inside the module directory. This directory is where user-installed packages are dropped. A .pth file in this directory is maintained, which contains paths to the directories where the extra packages are installed. In this article, you will learn how to find the location of Python’s site-packages directory in Python.

Finding the directory where the site packages are stored could be done in two ways:

  • Finding the site-packages directory containing all the packages installed in the Python distribution.
  • Finding the package directory of a specific package/library.

Finding the site-packages directory

The Global site-packages directory (or dist-packages) could be located by running the following command in the command interpreter (cmd.exe or terminal) of your Operating System:

py -m site

Output:

 

This gives a list of all the packages installed on the user and base sites, including the directories listed in the sys.path file. Hence the output of the previous command is verbose. To streamline it, call the getsitepackages function present in the site library. This could be compiled into a one-liner using the -c attribute present in the Python command, which executes the code given in the argument.

py -c "import site; print(site.getsitepackages())"

Output:

 

This gives a list containing the path of site-packages and the default python distribution where the site-packages directory would contain the list of all the packages installed in Python. 

Finding the package directory of a specific package

To locate the directory in which a particular module/library is installed, run the following command in the command interpreter of the operating system:

py -m pip show <package_name>

For demonstration, the package directory of pyautogui would be found. Hence, the command becomes:

py -m pip show pyautogui

Output:

 

This shows all the information associated with the package along with the directory in which it is located, which is the site-packages directory. This is because it is the parent directory of all the packages. Hence, a package directory could be located by searching for its name inside the site-packages directory.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads