blob: c97fd4e1c919fd372ad3d74eb531d1b886cedebd [file] [log] [blame]
Guido van Rossum571391b1997-04-03 22:41:49 +00001\section{Standard Module \sectcode{site}}
2\stmodindex{site}
3
4Scripts or modules that need to use site-specific modules should
5execute \code{import site} somewhere near the top of their code. This
6will append up to two site-specific paths (\code{sys.prefix +
7'/lib/site-python'} and
8\code{sys.exec_prefix + '/lib/site-python'}) to the module search path.
9\code{sys.prefix} and \code{sys.exec_prefix} are configured when Python is installed; the default value is \file{/usr/local}.
10
11Because of Python's import semantics, it is okay for more than one
12module to import \code{site} -- only the first one will execute the
13site customizations. The directories are only appended to the path if
14they exist and are not already on it.
15
16Sites that wish to provide site-specific modules should place them in
17one of the site specific directories; \code{sys.prefix +
18'/lib/site-python'} is for Python source code and
19\code{sys.exec_prefix + '/lib/site-python'} is for dynamically
20loadable extension modules (shared libraries).
21
22After these path manipulations, an attempt is made to import a module
23named \code{sitecustomize}, which can perform arbitrary site-specific
24customizations. If this import fails with an \code{ImportError}
25exception, it is ignored.
26
27Note that for non-Unix systems, \code{sys.prefix} and
28\code{sys.exec_prefix} are empty, and the path manipulations are
29skipped; however the import of \code{sitecustomize} is still attempted.