New in version 3.2.
Source code:Lib/sysconfig.py
Thesysconfig module provides access to Python’s configurationinformation like the list of installation paths and the configuration variablesrelevant for the current platform.
A Python distribution contains aMakefile and apyconfig.hheader file that are necessary to build both the Python binary itself andthird-party C extensions compiled usingdistutils.
sysconfig puts all variables found in these files in a dictionary thatcan be accessed usingget_config_vars() orget_config_var().
Notice that on Windows, it’s a much smaller set.
With no arguments, return a dictionary of all configuration variablesrelevant for the current platform.
With arguments, return a list of values that result from looking up eachargument in the configuration variable dictionary.
For each argument, if the value is not found, returnNone.
Return the value of a single variablename. Equivalent toget_config_vars().get(name).
Ifname is not found, returnNone.
Example of usage:
>>>importsysconfig>>>sysconfig.get_config_var('Py_ENABLE_SHARED')0>>>sysconfig.get_config_var('LIBDIR')'/usr/local/lib'>>>sysconfig.get_config_vars('AR','CXX')['ar', 'g++']
Python uses an installation scheme that differs depending on the platform and onthe installation options. These schemes are stored insysconfig underunique identifiers based on the value returned byos.name.
Every new component that is installed usingdistutils or aDistutils-based system will follow the same scheme to copy its file in the rightplaces.
Python currently supports seven schemes:
Each scheme is itself composed of a series of paths and each path has a uniqueidentifier. Python currently uses eight paths:
sysconfig provides some functions to determine these paths.
Return a tuple containing all path names currently supported insysconfig.
Return an installation path corresponding to the pathname, from theinstall scheme namedscheme.
name has to be a value from the list returned byget_path_names().
sysconfig stores installation paths corresponding to each path name,for each platform, with variables to be expanded. For instance thestdlibpath for thent scheme is:{base}/Lib.
get_path() will use the variables returned byget_config_vars()to expand the path. All variables have default values for each platform soone may call this function and get the default value.
Ifscheme is provided, it must be a value from the list returned byget_scheme_names(). Otherwise, the default scheme for the currentplatform is used.
Ifvars is provided, it must be a dictionary of variables that will updatethe dictionary return byget_config_vars().
Ifexpand is set toFalse, the path will not be expanded using thevariables.
Ifname is not found, returnNone.
Return a dictionary containing all installation paths corresponding to aninstallation scheme. Seeget_path() for more information.
Ifscheme is not provided, will use the default scheme for the currentplatform.
Ifvars is provided, it must be a dictionary of variables that willupdate the dictionary used to expand the paths.
Ifexpand is set to False, the paths will not be expanded.
Ifscheme is not an existing scheme,get_paths() will raise aKeyError.
Return theMAJOR.MINOR Python version number as a string. Similar tosys.version[:3].
Return a string that identifies the current platform.
This is used mainly to distinguish platform-specific build directories andplatform-specific built distributions. Typically includes the OS name andversion and the architecture (as supplied byos.uname()), although theexact information included depends on the OS; e.g. for IRIX the architectureisn’t particularly important (IRIX only runs on SGI hardware), but for Linuxthe kernel version isn’t particularly important.
Examples of returned values:
Windows will return one of:
Mac OS X can return:
For other non-POSIX platforms, currently just returnssys.platform.
ReturnTrue if the current Python installation was built from source.
Parse aconfig.h-style file.
fp is a file-like object pointing to theconfig.h-like file.
A dictionary containing name/value pairs is returned. If an optionaldictionary is passed in as the second argument, it is used instead of a newdictionary, and updated with the values read in the file.
Return the path ofpyconfig.h.
Return the path ofMakefile.
You can usesysconfig as a script with Python’s-m option:
$ python -m sysconfigPlatform: "macosx-10.4-i386"Python version: "3.2"Current installation scheme: "posix_prefix"Paths: data = "/usr/local" include = "/Users/tarek/Dev/svn.python.org/py3k/Include" platinclude = "." platlib = "/usr/local/lib/python3.2/site-packages" platstdlib = "/usr/local/lib/python3.2" purelib = "/usr/local/lib/python3.2/site-packages" scripts = "/usr/local/bin" stdlib = "/usr/local/lib/python3.2"Variables: AC_APPLE_UNIVERSAL_BUILD = "0" AIX_GENUINE_CPLUSPLUS = "0" AR = "ar" ARFLAGS = "rc" ASDLGEN = "./Parser/asdl_c.py" ...
This call will print in the standard output the information returned byget_platform(),get_python_version(),get_path() andget_config_vars().
28.1.sys — System-specific parameters and functions
28.3.builtins — Built-in objects
Enter search terms or a module, class or function name.