source: vendor/python/2.5/Doc/lib/libsite.tex

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 3.3 KB
Line 
1\section{\module{site} ---
2 Site-specific configuration hook}
3
4\declaremodule{standard}{site}
5\modulesynopsis{A standard way to reference site-specific modules.}
6
7
8\strong{This module is automatically imported during initialization.}
9The automatic import can be suppressed using the interpreter's
10\programopt{-S} option.
11
12Importing this module will append site-specific paths to the module
13search path.
14\indexiii{module}{search}{path}
15
16It starts by constructing up to four directories from a head and a
17tail part. For the head part, it uses \code{sys.prefix} and
18\code{sys.exec_prefix}; empty heads are skipped. For
19the tail part, it uses the empty string and then
20\file{lib/site-packages} (on Windows) or
21\file{lib/python\shortversion/site-packages} and then
22\file{lib/site-python} (on \UNIX{} and Macintosh). For each of the
23distinct head-tail combinations, it sees if it refers to an existing
24directory, and if so, adds it to \code{sys.path} and also inspects
25the newly added path for configuration files.
26\indexii{site-python}{directory}
27\indexii{site-packages}{directory}
28
29A path configuration file is a file whose name has the form
30\file{\var{package}.pth} and exists in one of the four directories
31mentioned above; its contents are additional items (one
32per line) to be added to \code{sys.path}. Non-existing items are
33never added to \code{sys.path}, but no check is made that the item
34refers to a directory (rather than a file). No item is added to
35\code{sys.path} more than once. Blank lines and lines beginning with
36\code{\#} are skipped. Lines starting with \code{import} are executed.
37\index{package}
38\indexiii{path}{configuration}{file}
39
40For example, suppose \code{sys.prefix} and \code{sys.exec_prefix} are
41set to \file{/usr/local}. The Python \version\ library is then
42installed in \file{/usr/local/lib/python\shortversion} (where only the
43first three characters of \code{sys.version} are used to form the
44installation path name). Suppose this has a subdirectory
45\file{/usr/local/lib/python\shortversion/site-packages} with three
46subsubdirectories, \file{foo}, \file{bar} and \file{spam}, and two
47path configuration files, \file{foo.pth} and \file{bar.pth}. Assume
48\file{foo.pth} contains the following:
49
50\begin{verbatim}
51# foo package configuration
52
53foo
54bar
55bletch
56\end{verbatim}
57
58and \file{bar.pth} contains:
59
60\begin{verbatim}
61# bar package configuration
62
63bar
64\end{verbatim}
65
66Then the following directories are added to \code{sys.path}, in this
67order:
68
69\begin{verbatim}
70/usr/local/lib/python2.3/site-packages/bar
71/usr/local/lib/python2.3/site-packages/foo
72\end{verbatim}
73
74Note that \file{bletch} is omitted because it doesn't exist; the
75\file{bar} directory precedes the \file{foo} directory because
76\file{bar.pth} comes alphabetically before \file{foo.pth}; and
77\file{spam} is omitted because it is not mentioned in either path
78configuration file.
79
80After these path manipulations, an attempt is made to import a module
81named \module{sitecustomize}\refmodindex{sitecustomize}, which can
82perform arbitrary site-specific customizations. If this import fails
83with an \exception{ImportError} exception, it is silently ignored.
84
85Note that for some non-\UNIX{} systems, \code{sys.prefix} and
86\code{sys.exec_prefix} are empty, and the path manipulations are
87skipped; however the import of
88\module{sitecustomize}\refmodindex{sitecustomize} is still attempted.
Note: See TracBrowser for help on using the repository browser.