2010-02-02 18:27:58 -04:00
|
|
|
:mod:`sysconfig` --- Provide access to Python's configuration information
|
|
|
|
=========================================================================
|
|
|
|
|
|
|
|
.. module:: sysconfig
|
|
|
|
:synopsis: Python's configuration information
|
|
|
|
.. moduleauthor:: Tarek Ziade <tarek@ziade.org>
|
|
|
|
.. sectionauthor:: Tarek Ziade <tarek@ziade.org>
|
|
|
|
.. versionadded:: 2.7
|
|
|
|
.. index::
|
|
|
|
single: configuration information
|
|
|
|
|
|
|
|
The :mod:`sysconfig` module provides access to Python's configuration
|
2010-02-06 06:23:16 -04:00
|
|
|
information like the list of installation paths and the configuration variables
|
|
|
|
relevant for the current platform.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
Configuration variables
|
|
|
|
-----------------------
|
|
|
|
|
2010-05-05 22:09:47 -03:00
|
|
|
A Python distribution contains a :file:`Makefile` and a :file:`pyconfig.h`
|
|
|
|
header file that are necessary to build both the Python binary itself and
|
|
|
|
third-party C extensions compiled using :mod:`distutils`.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
:mod:`sysconfig` puts all variables found in these files in a dictionary that
|
|
|
|
can be accessed using :func:`get_config_vars` or :func:`get_config_var`.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
Notice that on Windows, it's a much smaller set.
|
|
|
|
|
|
|
|
.. function:: get_config_vars(\*args)
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
With no arguments, return a dictionary of all configuration variables
|
|
|
|
relevant for the current platform.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
With arguments, return a list of values that result from looking up each
|
|
|
|
argument in the configuration variable dictionary.
|
|
|
|
|
|
|
|
For each argument, if the value is not found, return ``None``.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
.. function:: get_config_var(name)
|
|
|
|
|
|
|
|
Return the value of a single variable *name*. Equivalent to
|
2010-02-06 06:23:16 -04:00
|
|
|
``get_config_vars().get(name)``.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
If *name* is not found, return ``None``.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
Example of usage::
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
>>> import sysconfig
|
|
|
|
>>> sysconfig.get_config_var('Py_ENABLE_SHARED')
|
|
|
|
0
|
|
|
|
>>> sysconfig.get_config_var('LIBDIR')
|
|
|
|
'/usr/local/lib'
|
|
|
|
>>> sysconfig.get_config_vars('AR', 'CXX')
|
|
|
|
['ar', 'g++']
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
Installation paths
|
|
|
|
------------------
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
Python uses an installation scheme that differs depending on the platform and on
|
|
|
|
the installation options. These schemes are stored in :mod:`sysconfig` under
|
|
|
|
unique identifiers based on the value returned by :const:`os.name`.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
Every new component that is installed using :mod:`distutils` or a
|
2010-02-06 06:23:16 -04:00
|
|
|
Distutils-based system will follow the same scheme to copy its file in the right
|
|
|
|
places.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
Python currently supports seven schemes:
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
- *posix_prefix*: scheme for Posix platforms like Linux or Mac OS X. This is
|
|
|
|
the default scheme used when Python or a component is installed.
|
|
|
|
- *posix_home*: scheme for Posix platforms used when a *home* option is used
|
|
|
|
upon installation. This scheme is used when a component is installed through
|
2010-02-02 18:27:58 -04:00
|
|
|
Distutils with a specific home prefix.
|
2010-02-06 06:23:16 -04:00
|
|
|
- *posix_user*: scheme for Posix platforms used when a component is installed
|
|
|
|
through Distutils and the *user* option is used. This scheme defines paths
|
2010-02-02 18:27:58 -04:00
|
|
|
located under the user home directory.
|
2010-02-06 06:23:16 -04:00
|
|
|
- *nt*: scheme for NT platforms like Windows.
|
|
|
|
- *nt_user*: scheme for NT platforms, when the *user* option is used.
|
|
|
|
- *os2*: scheme for OS/2 platforms.
|
|
|
|
- *os2_home*: scheme for OS/2 patforms, when the *user* option is used.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
Each scheme is itself composed of a series of paths and each path has a unique
|
2010-02-06 06:23:16 -04:00
|
|
|
identifier. Python currently uses eight paths:
|
2010-02-02 18:27:58 -04:00
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
- *stdlib*: directory containing the standard Python library files that are not
|
|
|
|
platform-specific.
|
|
|
|
- *platstdlib*: directory containing the standard Python library files that are
|
|
|
|
platform-specific.
|
|
|
|
- *platlib*: directory for site-specific, platform-specific files.
|
|
|
|
- *purelib*: directory for site-specific, non-platform-specific files.
|
|
|
|
- *include*: directory for non-platform-specific header files.
|
|
|
|
- *platinclude*: directory for platform-specific header files.
|
|
|
|
- *scripts*: directory for script files.
|
|
|
|
- *data*: directory for data files.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
:mod:`sysconfig` provides some functions to determine these paths.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
.. function:: get_scheme_names()
|
|
|
|
|
|
|
|
Return a tuple containing all schemes currently supported in
|
|
|
|
:mod:`sysconfig`.
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
|
2010-02-02 18:27:58 -04:00
|
|
|
.. function:: get_path_names()
|
|
|
|
|
|
|
|
Return a tuple containing all path names currently supported in
|
|
|
|
:mod:`sysconfig`.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: get_path(name, [scheme, [vars, [expand]]])
|
|
|
|
|
|
|
|
Return an installation path corresponding to the path *name*, from the
|
|
|
|
install scheme named *scheme*.
|
|
|
|
|
|
|
|
*name* has to be a value from the list returned by :func:`get_path_names`.
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
:mod:`sysconfig` stores installation paths corresponding to each path name,
|
|
|
|
for each platform, with variables to be expanded. For instance the *stdlib*
|
|
|
|
path for the *nt* scheme is: ``{base}/Lib``.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
:func:`get_path` will use the variables returned by :func:`get_config_vars`
|
2010-02-06 06:23:16 -04:00
|
|
|
to expand the path. All variables have default values for each platform so
|
|
|
|
one may call this function and get the default value.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
If *scheme* is provided, it must be a value from the list returned by
|
2010-02-06 06:23:16 -04:00
|
|
|
:func:`get_path_names`. Otherwise, the default scheme for the current
|
2010-02-02 18:27:58 -04:00
|
|
|
platform is used.
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
If *vars* is provided, it must be a dictionary of variables that will update
|
|
|
|
the dictionary return by :func:`get_config_vars`.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
If *expand* is set to ``False``, the path will not be expanded using the
|
|
|
|
variables.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
If *name* is not found, return ``None``.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
.. function:: get_paths([scheme, [vars, [expand]]])
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
Return a dictionary containing all installation paths corresponding to an
|
2010-02-02 18:27:58 -04:00
|
|
|
installation scheme. See :func:`get_path` for more information.
|
|
|
|
|
|
|
|
If *scheme* is not provided, will use the default scheme for the current
|
|
|
|
platform.
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
If *vars* is provided, it must be a dictionary of variables that will
|
|
|
|
update the dictionary used to expand the paths.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
If *expand* is set to False, the paths will not be expanded.
|
|
|
|
|
|
|
|
If *scheme* is not an existing scheme, :func:`get_paths` will raise a
|
|
|
|
:exc:`KeyError`.
|
|
|
|
|
|
|
|
|
|
|
|
Other functions
|
|
|
|
---------------
|
|
|
|
|
|
|
|
.. function:: get_python_version()
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
Return the ``MAJOR.MINOR`` Python version number as a string. Similar to
|
2010-02-02 18:27:58 -04:00
|
|
|
``sys.version[:3]``.
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
|
2010-02-02 18:27:58 -04:00
|
|
|
.. function:: get_platform()
|
|
|
|
|
|
|
|
Return a string that identifies the current platform.
|
|
|
|
|
|
|
|
This is used mainly to distinguish platform-specific build directories and
|
2010-02-06 06:23:16 -04:00
|
|
|
platform-specific built distributions. Typically includes the OS name and
|
|
|
|
version and the architecture (as supplied by :func:`os.uname`), although the
|
|
|
|
exact information included depends on the OS; e.g. for IRIX the architecture
|
|
|
|
isn't particularly important (IRIX only runs on SGI hardware), but for Linux
|
|
|
|
the kernel version isn't particularly important.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
Examples of returned values:
|
|
|
|
|
|
|
|
- linux-i586
|
|
|
|
- linux-alpha (?)
|
|
|
|
- solaris-2.6-sun4u
|
|
|
|
- irix-5.3
|
|
|
|
- irix64-6.2
|
|
|
|
|
|
|
|
Windows will return one of:
|
|
|
|
|
|
|
|
- win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
|
|
|
|
- win-ia64 (64bit Windows on Itanium)
|
|
|
|
- win32 (all others - specifically, sys.platform is returned)
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
Mac OS X can return:
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
- macosx-10.6-ppc
|
|
|
|
- macosx-10.4-ppc64
|
|
|
|
- macosx-10.3-i386
|
|
|
|
- macosx-10.4-fat
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
For other non-POSIX platforms, currently just returns :data:`sys.platform`.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
.. function:: is_python_build()
|
2010-02-02 18:27:58 -04:00
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
Return ``True`` if the current Python installation was built from source.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
.. function:: parse_config_h(fp[, vars])
|
2010-02-02 18:27:58 -04:00
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
Parse a :file:`config.h`\-style file.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
*fp* is a file-like object pointing to the :file:`config.h`\-like file.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
A dictionary containing name/value pairs is returned. If an optional
|
2010-02-06 06:23:16 -04:00
|
|
|
dictionary is passed in as the second argument, it is used instead of a new
|
|
|
|
dictionary, and updated with the values read in the file.
|
2010-02-02 18:27:58 -04:00
|
|
|
|
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
.. function:: get_config_h_filename()
|
2010-02-02 18:27:58 -04:00
|
|
|
|
2010-02-06 06:23:16 -04:00
|
|
|
Return the path of :file:`pyconfig.h`.
|