Module site
[hide private]
[frames] | no frames]

Module site

Append module search paths for third-party packages to sys.path.

****************************************************************
* This module is automatically imported during initialization. *
****************************************************************

In earlier versions of Python (up to 1.5a3), scripts or modules that
needed to use site-specific modules would place ``import site''
somewhere near the top of their code.  Because of the automatic
import, this is no longer necessary (but code that does it still
works).

This will append site-specific paths to the module search path.  On
Unix (including Mac OSX), it starts with sys.prefix and
sys.exec_prefix (if different) and appends
lib/python<version>/site-packages as well as lib/site-python.
On other platforms (such as Windows), it tries each of the
prefixes directly, as well as with lib/site-packages appended.  The
resulting directories, if they exist, are appended to sys.path, and
also inspected for path configuration files.

FOR DEBIAN, this sys.path is augmented with directories in /usr/local.
Local addons go into /usr/local/lib/python<version>/site-packages
(resp. /usr/local/lib/site-python), Debian addons install into
/usr/{lib,share}/python<version>/site-packages.

A path configuration file is a file whose name has the form
<package>.pth; its contents are additional directories (one per line)
to be added to sys.path.  Non-existing directories (or
non-directories) are never added to sys.path; no directory is added to
sys.path more than once.  Blank lines and lines beginning with
'#' are skipped. Lines starting with 'import' are executed.

For example, suppose sys.prefix and sys.exec_prefix are set to
/usr/local and there is a directory /usr/local/lib/python2.5/site-packages
with three subdirectories, foo, bar and spam, and two path
configuration files, foo.pth and bar.pth.  Assume foo.pth contains the
following:

  # foo package configuration
  foo
  bar
  bletch

and bar.pth contains:

  # bar package configuration
  bar

Then the following directories are added to sys.path, in this order:

  /usr/local/lib/python2.5/site-packages/bar
  /usr/local/lib/python2.5/site-packages/foo

Note that bletch is omitted because it doesn't exist; bar precedes foo
because bar.pth comes alphabetically before foo.pth; and spam is
omitted because it is not mentioned in either path configuration file.

After these path manipulations, an attempt is made to import a module
named sitecustomize, which can perform arbitrary additional
site-specific customizations.  If this import fails with an
ImportError exception, it is silently ignored.

Classes [hide private]
_Printer
interactive prompt objects for printing the license text, a list of contributors and the copyright notice.
_Helper
Define the built-in 'help'.
Functions [hide private]
 
makepath(*paths)
 
abs__file__()
Set all module' __file__ attribute to an absolute path
 
removeduppaths()
Remove duplicate entries from sys.path along with making them absolute
 
addbuilddir()
Append ./build/lib.<platform> in case we're running in the build dir (especially for Guido :-)
 
_init_pathinfo()
Return a set containing all existing directory entries from sys.path
 
addpackage(sitedir, name, known_paths)
Add a new path to known_paths by combining sitedir and 'name' or execute sitedir if it starts with 'import'
 
addsitedir(sitedir, known_paths=None)
Add 'sitedir' argument to sys.path if missing and handle .pth files in 'sitedir'
 
addsitepackages(known_paths)
Add site-packages (and possibly site-python) to sys.path
 
setBEGINLIBPATH()
The OS/2 EMX port has optional extension modules that do double duty as DLLs (and must use the .DLL file extension) for other extensions.
 
setquit()
Define new built-ins 'quit' and 'exit'.
 
setcopyright()
Set 'copyright' and 'credits' in __builtin__
 
sethelper()
 
aliasmbcs()
On Windows, some default encodings are not provided by Python, while they are always available as "mbcs" in each locale.
 
setencoding()
Set the string encoding used by the Unicode implementation.
 
execsitecustomize()
Run custom site specific code, if available.
 
main()
 
_test()

Imports: sys, os, __builtin__


Function Details [hide private]

setBEGINLIBPATH()

 

The OS/2 EMX port has optional extension modules that do double duty as DLLs (and must use the .DLL file extension) for other extensions. The library search path needs to be amended so these will be found during module import. Use BEGINLIBPATH so that these are at the start of the library search path.

setquit()

 

Define new built-ins 'quit' and 'exit'. These are simply strings that display a hint on how to exit.

aliasmbcs()

 

On Windows, some default encodings are not provided by Python, while they are always available as "mbcs" in each locale. Make them usable by aliasing to "mbcs" in such a case.

setencoding()

 

Set the string encoding used by the Unicode implementation. The default is 'ascii', but if you're willing to experiment, you can change this.