|
5261
|
1 \section{Standard Module \sectcode{site}}
|
|
|
2 \stmodindex{site}
|
|
|
3
|
|
|
4 Scripts or modules that need to use site-specific modules should
|
|
|
5 execute \code{import site} somewhere near the top of their code. This
|
|
|
6 will 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
|
|
|
11 Because of Python's import semantics, it is okay for more than one
|
|
|
12 module to import \code{site} -- only the first one will execute the
|
|
|
13 site customizations. The directories are only appended to the path if
|
|
|
14 they exist and are not already on it.
|
|
|
15
|
|
|
16 Sites that wish to provide site-specific modules should place them in
|
|
|
17 one 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
|
|
|
20 loadable extension modules (shared libraries).
|
|
|
21
|
|
|
22 After these path manipulations, an attempt is made to import a module
|
|
|
23 named \code{sitecustomize}, which can perform arbitrary site-specific
|
|
|
24 customizations. If this import fails with an \code{ImportError}
|
|
|
25 exception, it is ignored.
|
|
|
26
|
|
|
27 Note that for non-Unix systems, \code{sys.prefix} and
|
|
|
28 \code{sys.exec_prefix} are empty, and the path manipulations are
|
|
|
29 skipped; however the import of \code{sitecustomize} is still attempted.
|