| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="module-user.html" /> |
| 13 | <link rel="prev" href="module-new.html" /> |
| 14 | <link rel="parent" href="python.html" /> |
| 15 | <link rel="next" href="module-user.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>3.30 site -- Site-specific configuration hook</title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="3.29 new " |
| 25 | href="module-new.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="3. Python Runtime Services" |
| 28 | href="python.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="3.31 user " |
| 31 | href="module-user.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python Library Reference</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 38 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="module-new.html">3.29 new </A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="module-user.html">3.31 user </A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H1><A NAME="SECTION0053000000000000000000"> |
| 56 | 3.30 <tt class="module">site</tt> -- |
| 57 | Site-specific configuration hook</A> |
| 58 | </H1> |
| 59 | |
| 60 | <P> |
| 61 | <A NAME="module-site"></A> |
| 62 | |
| 63 | <P> |
| 64 | <strong>This module is automatically imported during initialization.</strong> |
| 65 | The automatic import can be suppressed using the interpreter's |
| 66 | <b class="programopt">-S</b> option. |
| 67 | |
| 68 | <P> |
| 69 | Importing this module will append site-specific paths to the module |
| 70 | search path. |
| 71 | <a id='l2h-800' xml:id='l2h-800'></a> |
| 72 | <P> |
| 73 | It starts by constructing up to four directories from a head and a |
| 74 | tail part. For the head part, it uses <code>sys.prefix</code> and |
| 75 | <code>sys.exec_prefix</code>; empty heads are skipped. For |
| 76 | the tail part, it uses the empty string (on Windows) or |
| 77 | <span class="file">lib/python2.4/site-packages</span> (on <span class="Unix">Unix</span> and Macintosh) |
| 78 | and then <span class="file">lib/site-python</span>. For each of the distinct |
| 79 | head-tail combinations, it sees if it refers to an existing directory, |
| 80 | and if so, adds it to <code>sys.path</code> and also inspects the newly added |
| 81 | path for configuration files. |
| 82 | <a id='l2h-801' xml:id='l2h-801'></a><a id='l2h-802' xml:id='l2h-802'></a> |
| 83 | <P> |
| 84 | A path configuration file is a file whose name has the form |
| 85 | <span class="file"><var>package</var>.pth</span> and exists in one of the four directories |
| 86 | mentioned above; its contents are additional items (one |
| 87 | per line) to be added to <code>sys.path</code>. Non-existing items are |
| 88 | never added to <code>sys.path</code>, but no check is made that the item |
| 89 | refers to a directory (rather than a file). No item is added to |
| 90 | <code>sys.path</code> more than once. Blank lines and lines beginning with |
| 91 | <code>#</code> are skipped. Lines starting with <code>import</code> are executed. |
| 92 | <a id='l2h-804' xml:id='l2h-804'></a> |
| 93 | <a id='l2h-803' xml:id='l2h-803'></a> |
| 94 | <P> |
| 95 | For example, suppose <code>sys.prefix</code> and <code>sys.exec_prefix</code> are |
| 96 | set to <span class="file">/usr/local</span>. The Python 2.4.2 library is then |
| 97 | installed in <span class="file">/usr/local/lib/python2.4</span> (where only the |
| 98 | first three characters of <code>sys.version</code> are used to form the |
| 99 | installation path name). Suppose this has a subdirectory |
| 100 | <span class="file">/usr/local/lib/python2.4/site-packages</span> with three |
| 101 | subsubdirectories, <span class="file">foo</span>, <span class="file">bar</span> and <span class="file">spam</span>, and two |
| 102 | path configuration files, <span class="file">foo.pth</span> and <span class="file">bar.pth</span>. Assume |
| 103 | <span class="file">foo.pth</span> contains the following: |
| 104 | |
| 105 | <P> |
| 106 | <div class="verbatim"><pre> |
| 107 | # foo package configuration |
| 108 | |
| 109 | foo |
| 110 | bar |
| 111 | bletch |
| 112 | </pre></div> |
| 113 | |
| 114 | <P> |
| 115 | and <span class="file">bar.pth</span> contains: |
| 116 | |
| 117 | <P> |
| 118 | <div class="verbatim"><pre> |
| 119 | # bar package configuration |
| 120 | |
| 121 | bar |
| 122 | </pre></div> |
| 123 | |
| 124 | <P> |
| 125 | Then the following directories are added to <code>sys.path</code>, in this |
| 126 | order: |
| 127 | |
| 128 | <P> |
| 129 | <div class="verbatim"><pre> |
| 130 | /usr/local/lib/python2.3/site-packages/bar |
| 131 | /usr/local/lib/python2.3/site-packages/foo |
| 132 | </pre></div> |
| 133 | |
| 134 | <P> |
| 135 | Note that <span class="file">bletch</span> is omitted because it doesn't exist; the |
| 136 | <span class="file">bar</span> directory precedes the <span class="file">foo</span> directory because |
| 137 | <span class="file">bar.pth</span> comes alphabetically before <span class="file">foo.pth</span>; and |
| 138 | <span class="file">spam</span> is omitted because it is not mentioned in either path |
| 139 | configuration file. |
| 140 | |
| 141 | <P> |
| 142 | After these path manipulations, an attempt is made to import a module |
| 143 | named <tt class="module">sitecustomize</tt><a id='l2h-805' xml:id='l2h-805'></a>, which can |
| 144 | perform arbitrary site-specific customizations. If this import fails |
| 145 | with an <tt class="exception">ImportError</tt> exception, it is silently ignored. |
| 146 | |
| 147 | <P> |
| 148 | Note that for some non-<span class="Unix">Unix</span> systems, <code>sys.prefix</code> and |
| 149 | <code>sys.exec_prefix</code> are empty, and the path manipulations are |
| 150 | skipped; however the import of |
| 151 | <tt class="module">sitecustomize</tt><a id='l2h-806' xml:id='l2h-806'></a> is still attempted. |
| 152 | |
| 153 | <DIV CLASS="navigation"> |
| 154 | <div class='online-navigation'> |
| 155 | <p></p><hr /> |
| 156 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 157 | <tr> |
| 158 | <td class='online-navigation'><a rel="prev" title="3.29 new " |
| 159 | href="module-new.html"><img src='../icons/previous.png' |
| 160 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 161 | <td class='online-navigation'><a rel="parent" title="3. Python Runtime Services" |
| 162 | href="python.html"><img src='../icons/up.png' |
| 163 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 164 | <td class='online-navigation'><a rel="next" title="3.31 user " |
| 165 | href="module-user.html"><img src='../icons/next.png' |
| 166 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 167 | <td align="center" width="100%">Python Library Reference</td> |
| 168 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 169 | href="contents.html"><img src='../icons/contents.png' |
| 170 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 171 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 172 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 173 | <td class='online-navigation'><a rel="index" title="Index" |
| 174 | href="genindex.html"><img src='../icons/index.png' |
| 175 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 176 | </tr></table> |
| 177 | <div class='online-navigation'> |
| 178 | <b class="navlabel">Previous:</b> |
| 179 | <a class="sectref" rel="prev" href="module-new.html">3.29 new </A> |
| 180 | <b class="navlabel">Up:</b> |
| 181 | <a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A> |
| 182 | <b class="navlabel">Next:</b> |
| 183 | <a class="sectref" rel="next" href="module-user.html">3.31 user </A> |
| 184 | </div> |
| 185 | </div> |
| 186 | <hr /> |
| 187 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 188 | </DIV> |
| 189 | <!--End of Navigation Panel--> |
| 190 | <ADDRESS> |
| 191 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 192 | </ADDRESS> |
| 193 | </BODY> |
| 194 | </HTML> |