Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / inst / search-path.html
CommitLineData
920dae64
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="inst.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="inst.html" title='Installing Python Modules' />
8<link rel='last' href='about.html' title='About this document...' />
9<link rel='help' href='about.html' title='About this document...' />
10<link rel="next" href="config-syntax.html" />
11<link rel="prev" href="alt-install-windows.html" />
12<link rel="parent" href="inst.html" />
13<link rel="next" href="config-syntax.html" />
14<meta name='aesop' content='information' />
15<title>4 Custom Installation</title>
16</head>
17<body>
18<DIV CLASS="navigation">
19<div id='top-navigation-panel' xml:id='top-navigation-panel'>
20<table align="center" width="100%" cellpadding="0" cellspacing="2">
21<tr>
22<td class='online-navigation'><a rel="prev" title="3 Alternate Installation"
23 href="alt-install-windows.html"><img src='../icons/previous.png'
24 border='0' height='32' alt='Previous Page' width='32' /></A></td>
25<td class='online-navigation'><a rel="parent" title="Installing Python Modules"
26 href="inst.html"><img src='../icons/up.png'
27 border='0' height='32' alt='Up One Level' width='32' /></A></td>
28<td class='online-navigation'><a rel="next" title="5 Distutils Configuration Files"
29 href="config-syntax.html"><img src='../icons/next.png'
30 border='0' height='32' alt='Next Page' width='32' /></A></td>
31<td align="center" width="100%">Installing Python Modules</td>
32<td class='online-navigation'><img src='../icons/blank.png'
33 border='0' height='32' alt='' width='32' /></td>
34<td class='online-navigation'><img src='../icons/blank.png'
35 border='0' height='32' alt='' width='32' /></td>
36<td class='online-navigation'><img src='../icons/blank.png'
37 border='0' height='32' alt='' width='32' /></td>
38</tr></table>
39<div class='online-navigation'>
40<b class="navlabel">Previous:</b>
41<a class="sectref" rel="prev" href="alt-install-windows.html">3 Alternate Installation</A>
42<b class="navlabel">Up:</b>
43<a class="sectref" rel="parent" href="inst.html">Installing Python Modules</A>
44<b class="navlabel">Next:</b>
45<a class="sectref" rel="next" href="config-syntax.html">5 Distutils Configuration Files</A>
46</div>
47<hr /></div>
48</DIV>
49<!--End of Navigation Panel-->
50<div class='online-navigation'>
51<!--Table of Child-Links-->
52<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
53
54<UL CLASS="ChildLinks">
55<LI><A href="search-path.html#SECTION000410000000000000000">4.1 Modifying Python's Search Path</a>
56</ul>
57<!--End of Table of Child-Links-->
58</div>
59<HR>
60
61<H1><A NAME="SECTION000400000000000000000"></A>
62<A NAME="custom-install"></A>
63<BR>
644 Custom Installation
65</H1>
66
67<P>
68Sometimes, the alternate installation schemes described in
69section&nbsp;<A href="alt-install-windows.html#alt-install">3</A> just don't do what you want. You might
70want to tweak just one or two directories while keeping everything under
71the same base directory, or you might want to completely redefine the
72installation scheme. In either case, you're creating a <em>custom
73installation scheme</em>.
74
75<P>
76You probably noticed the column of ``override options'' in the tables
77describing the alternate installation schemes above. Those options are
78how you define a custom installation scheme. These override options can
79be relative, absolute, or explicitly defined in terms of one of the
80installation base directories. (There are two installation base
81directories, and they are normally the same--they only differ when you
82use the <span class="Unix">Unix</span> ``prefix scheme'' and supply different
83<b class="programopt">--prefix</b> and <b class="programopt">--exec-prefix</b> options.)
84
85<P>
86For example, say you're installing a module distribution to your home
87directory under <span class="Unix">Unix</span>--but you want scripts to go in
88<span class="file">~/scripts</span> rather than <span class="file">~/bin</span>.
89As you might expect, you can override this directory with the
90<b class="programopt">--install-scripts</b> option; in this case, it makes most
91sense to supply a relative path, which will be interpreted relative to
92the installation base directory (your home directory, in this case):
93
94<P>
95<div class="verbatim"><pre>
96python setup.py install --home=~ --install-scripts=scripts
97</pre></div>
98
99<P>
100Another <span class="Unix">Unix</span> example: suppose your Python installation was built and
101installed with a prefix of <span class="file">/usr/local/python</span>, so under a standard
102installation scripts will wind up in <span class="file">/usr/local/python/bin</span>. If
103you want them in <span class="file">/usr/local/bin</span> instead, you would supply this
104absolute directory for the <b class="programopt">--install-scripts</b> option:
105
106<P>
107<div class="verbatim"><pre>
108python setup.py install --install-scripts=/usr/local/bin
109</pre></div>
110
111<P>
112(This performs an installation using the ``prefix scheme,'' where the
113prefix is whatever your Python interpreter was installed with--
114<span class="file">/usr/local/python</span> in this case.)
115
116<P>
117If you maintain Python on Windows, you might want third-party modules to
118live in a subdirectory of <span class="du-filevar">prefix</span>, rather than right in
119<span class="du-filevar">prefix</span> itself. This is almost as easy as customizing the
120script installation directory--you just have to remember that there are
121two types of modules to worry about, pure modules and non-pure modules
122(i.e., modules from a non-pure distribution). For example:
123
124<P>
125<div class="verbatim"><pre>
126python setup.py install --install-purelib=Site --install-platlib=Site
127</pre></div>
128
129<P>
130The specified installation directories are relative to
131<span class="du-filevar">prefix</span>. Of course, you also have to ensure that these
132directories are in Python's module search path, such as by putting a
133<span class="file">.pth</span> file in <span class="du-filevar">prefix</span>. See section&nbsp;<A HREF="#search-path">4.1</A>
134to find out how to modify Python's search path.
135
136<P>
137If you want to define an entire installation scheme, you just have to
138supply all of the installation directory options. The recommended way
139to do this is to supply relative paths; for example, if you want to
140maintain all Python module-related files under <span class="file">python</span> in your
141home directory, and you want a separate directory for each platform that
142you use your home directory from, you might define the following
143installation scheme:
144
145<P>
146<div class="verbatim"><pre>
147python setup.py install --home=~ \
148 --install-purelib=python/lib \
149 --install-platlib=python/lib.$PLAT \
150 --install-scripts=python/scripts
151 --install-data=python/data
152</pre></div>
153
154<P>
155or, equivalently,
156
157<P>
158<div class="verbatim"><pre>
159python setup.py install --home=~/python \
160 --install-purelib=lib \
161 --install-platlib='lib.$PLAT' \
162 --install-scripts=scripts
163 --install-data=data
164</pre></div>
165
166<P>
167<code>$PLAT</code> is not (necessarily) an environment variable--it will be
168expanded by the Distutils as it parses your command line options, just
169as it does when parsing your configuration file(s).
170
171<P>
172Obviously, specifying the entire installation scheme every time you
173install a new module distribution would be very tedious. Thus, you can
174put these options into your Distutils config file (see
175section&nbsp;<A href="config-syntax.html#config-files">5</A>):
176
177<P>
178<div class="verbatim"><pre>
179[install]
180install-base=$HOME
181install-purelib=python/lib
182install-platlib=python/lib.$PLAT
183install-scripts=python/scripts
184install-data=python/data
185</pre></div>
186
187<P>
188or, equivalently,
189
190<P>
191<div class="verbatim"><pre>
192[install]
193install-base=$HOME/python
194install-purelib=lib
195install-platlib=lib.$PLAT
196install-scripts=scripts
197install-data=data
198</pre></div>
199
200<P>
201Note that these two are <em>not</em> equivalent if you supply a different
202installation base directory when you run the setup script. For example,
203
204<P>
205<div class="verbatim"><pre>
206python setup.py --install-base=/tmp
207</pre></div>
208
209<P>
210would install pure modules to <span class="du-filevar">/tmp/python/lib</span> in the first
211case, and to <span class="du-filevar">/tmp/lib</span> in the second case. (For the second
212case, you probably want to supply an installation base of
213<span class="file">/tmp/python</span>.)
214
215<P>
216You probably noticed the use of <code>$HOME</code> and <code>$PLAT</code> in the
217sample configuration file input. These are Distutils configuration
218variables, which bear a strong resemblance to environment variables.
219In fact, you can use environment variables in config files on
220platforms that have such a notion but the Distutils additionally
221define a few extra variables that may not be in your environment, such
222as <code>$PLAT</code>. (And of course, on systems that don't have
223environment variables, such as Mac OS 9, the configuration
224variables supplied by the Distutils are the only ones you can use.)
225See section&nbsp;<A href="config-syntax.html#config-files">5</A> for details.
226
227<P>
228
229<H2><A NAME="SECTION000410000000000000000"></A>
230<A NAME="search-path"></A>
231<BR>
2324.1 Modifying Python's Search Path
233</H2>
234
235<P>
236When the Python interpreter executes an <tt class="keyword">import</tt> statement, it
237searches for both Python code and extension modules along a search
238path. A default value for the path is configured into the Python
239binary when the interpreter is built. You can determine the path by
240importing the <tt class="module">sys</tt> module and printing the value of
241<code>sys.path</code>.
242
243<P>
244<div class="verbatim"><pre>
245$ python
246Python 2.2 (#11, Oct 3 2002, 13:31:27)
247[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2
248Type ``help'', ``copyright'', ``credits'' or ``license'' for more information.
249&gt;&gt;&gt; import sys
250&gt;&gt;&gt; sys.path
251['', '/usr/local/lib/python2.3', '/usr/local/lib/python2.3/plat-linux2',
252 '/usr/local/lib/python2.3/lib-tk', '/usr/local/lib/python2.3/lib-dynload',
253 '/usr/local/lib/python2.3/site-packages']
254&gt;&gt;&gt;
255</pre></div>
256<P>
257The null string in <code>sys.path</code> represents the current working
258directory.
259
260<P>
261The expected convention for locally installed packages is to put them
262in the <span class="file">.../site-packages/</span> directory, but you may want to
263install Python modules into some arbitrary directory. For example,
264your site may have a convention of keeping all software related to the
265web server under <span class="file">/www</span>. Add-on Python modules might then belong
266in <span class="file">/www/python</span>, and in order to import them, this directory
267must be added to <code>sys.path</code>. There are several different ways to
268add the directory.
269
270<P>
271The most convenient way is to add a path configuration file to a
272directory that's already on Python's path, usually to the
273<span class="file">.../site-packages/</span> directory. Path configuration files have an
274extension of <span class="file">.pth</span>, and each line must contain a single path
275that will be appended to <code>sys.path</code>. (Because the new paths are
276appended to <code>sys.path</code>, modules in the added directories will not
277override standard modules. This means you can't use this mechanism
278for installing fixed versions of standard modules.)
279
280<P>
281Paths can be absolute or relative, in which case they're relative to
282the directory containing the <span class="file">.pth</span> file. Any directories added
283to the search path will be scanned in turn for <span class="file">.pth</span> files. See
284<em class="citetitle"><a
285 href="http://www.python.org/dev/doc/devel/lib/module-site.html"
286 title="site module documentation"
287 >site module documentation</a></em> for more information.
288
289<P>
290A slightly less convenient way is to edit the <span class="file">site.py</span> file in
291Python's standard library, and modify <code>sys.path</code>. <span class="file">site.py</span>
292is automatically imported when the Python interpreter is executed,
293unless the <b class="programopt">-S</b> switch is supplied to suppress this
294behaviour. So you could simply edit <span class="file">site.py</span> and add two lines to it:
295
296<P>
297<div class="verbatim"><pre>
298import sys
299sys.path.append('/www/python/')
300</pre></div>
301
302<P>
303However, if you reinstall the same major version of Python (perhaps
304when upgrading from 2.2 to 2.2.2, for example) <span class="file">site.py</span> will be
305overwritten by the stock version. You'd have to remember that it was
306modified and save a copy before doing the installation.
307
308<P>
309There are two environment variables that can modify <code>sys.path</code>.
310<a class="envvar" id='l2h-1' xml:id='l2h-1'>PYTHONHOME</a> sets an alternate value for the prefix of the
311Python installation. For example, if <a class="envvar" id='l2h-2' xml:id='l2h-2'>PYTHONHOME</a> is set to
312"<tt class="samp">/www/python</tt>", the search path will be set to <code>['',
313'/www/python/lib/python2.2/', '/www/python/lib/python2.3/plat-linux2',
314...]</code>.
315
316<P>
317The <a class="envvar" id='l2h-3' xml:id='l2h-3'>PYTHONPATH</a> variable can be set to a list of paths that
318will be added to the beginning of <code>sys.path</code>. For example, if
319<a class="envvar" id='l2h-4' xml:id='l2h-4'>PYTHONPATH</a> is set to "<tt class="samp">/www/python:/opt/py</tt>", the search
320path will begin with <code>['/www/python', '/opt/py']</code>. (Note that
321directories must exist in order to be added to <code>sys.path</code>; the
322<tt class="module">site</tt> module removes paths that don't exist.)
323
324<P>
325Finally, <code>sys.path</code> is just a regular Python list, so any Python
326application can modify it by adding or removing entries.
327
328<P>
329
330<DIV CLASS="navigation">
331<div class='online-navigation'>
332<p></p><hr />
333<table align="center" width="100%" cellpadding="0" cellspacing="2">
334<tr>
335<td class='online-navigation'><a rel="prev" title="3 Alternate Installation"
336 href="alt-install-windows.html"><img src='../icons/previous.png'
337 border='0' height='32' alt='Previous Page' width='32' /></A></td>
338<td class='online-navigation'><a rel="parent" title="Installing Python Modules"
339 href="inst.html"><img src='../icons/up.png'
340 border='0' height='32' alt='Up One Level' width='32' /></A></td>
341<td class='online-navigation'><a rel="next" title="5 Distutils Configuration Files"
342 href="config-syntax.html"><img src='../icons/next.png'
343 border='0' height='32' alt='Next Page' width='32' /></A></td>
344<td align="center" width="100%">Installing Python Modules</td>
345<td class='online-navigation'><img src='../icons/blank.png'
346 border='0' height='32' alt='' width='32' /></td>
347<td class='online-navigation'><img src='../icons/blank.png'
348 border='0' height='32' alt='' width='32' /></td>
349<td class='online-navigation'><img src='../icons/blank.png'
350 border='0' height='32' alt='' width='32' /></td>
351</tr></table>
352<div class='online-navigation'>
353<b class="navlabel">Previous:</b>
354<a class="sectref" rel="prev" href="alt-install-windows.html">3 Alternate Installation</A>
355<b class="navlabel">Up:</b>
356<a class="sectref" rel="parent" href="inst.html">Installing Python Modules</A>
357<b class="navlabel">Next:</b>
358<a class="sectref" rel="next" href="config-syntax.html">5 Distutils Configuration Files</A>
359</div>
360</div>
361<hr />
362<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
363</DIV>
364<!--End of Navigation Panel-->
365<ADDRESS>
366See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
367</ADDRESS>
368</BODY>
369</HTML>