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