W3docs

How do I find the location of my Python site-packages directory?

You can use the site module to find the location of your Python site-packages directory.

You can use the sysconfig module to find the location of your Python site-packages directory. Here is a code snippet that you can use:

Find the location of my Python site-packages directory

import sysconfig
print(sysconfig.get_paths()['purelib'])

This will return the path to the pure Python site-packages directory, which works reliably across different operating systems and virtual environments.

Alternatively, you can use the site module to find the location of the site-packages directory.

Find the location of my Python site-packages directory using the site module

import site
print(site.getsitepackages())

This will return a list of directories where site-packages are located. Note that site.getsitepackages() is deprecated in Python 3.10 and removed in 3.12, so sysconfig is recommended for modern Python versions.