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