Configuration information of Python's installation can be accessed by the sysconfig module. For example the list of installation paths and the configuration variables specific to the installation platform.
The sysconfig module provides the following functions to access Configuration variables
sysconfig.get_config_vars()
With no arguments, this function returns a dictionary of all configuration variables relevant for the current platform.
>>> import sysconfig >>> sysconfig.get_config_vars() {'prefix': 'E:\\python37', 'exec_prefix': 'E:\\python37', 'py_version': '3.7.2', 'py_version_short': '3.7', 'py_version_nodot': '37', 'installed_base': 'E:\\python37', 'base': 'E:\\python37', 'installed_platbase': 'E:\\python37', 'platbase': 'E:\\python37', 'projectbase': 'E:\\python37', 'abiflags': '', 'LIBDEST': 'E:\\python37\\Lib', 'BINLIBDEST': 'E:\\python37\\Lib', 'INCLUDEPY': 'E:\\python37\\Include', 'EXT_SUFFIX': '.pyd', 'EXE': '.exe', 'VERSION': '37', 'BINDIR': 'E:\\python37', 'SO': '.pyd', 'userbase': 'C:\\Users\\acer\\AppData\\Roaming\\Python', 'srcdir': 'E:\\python37'}
With arguments, return a list of values for specific keys. For each argument, if the value is not found, return None.
>>> sysconfig.get_config_vars('base','EXE') ['E:\\python37', '.exe']
sysconfig.get_config_var()
This function returns the value of a single variable name. This is equivalent to get_config_vars().get(name). If name is not found, the function returns None.
>>> sysconfig.get_config_var('VERSION') '37' >>> sysconfig.get_config_var('srcdir') 'E:\\python37'
Python uses an installation scheme that differs depending on the platform and on the installation options. Following schemes are currently supported:
posix_prefix | scheme for Posix platforms like Linux or Mac OS X. |
posix_home | scheme for Posix platforms used when a home option is used upon installation. |
posix_user | scheme for Posix platforms used when a component is installed through Distutils and the user option is used. |
nt | scheme for NT platforms like Windows. |
nt_user | scheme for NT platforms, when the user option is used |
get_path_names()
This function returns a tuple containing all path names currently supported in sysconfig.
>>> sysconfig.get_path_names() ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include', 'scripts', 'data')
Each scheme is composed of a various paths having unique identifier. The path names are as below:
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. |
get_path()
This function returns installation path corresponding to the path name, from the install scheme named scheme.
>>> sysconfig.get_path('include') 'E:\\python37\\Include'
>>> sysconfig.get_platform() 'win-amd64'
get_python_version()
This function returns the MAJOR.MINOR Python version number as a string.
get_platform()
This function returns a string that identifies the current platform.
The configuration variables and their values can also be accessed using sysconfig module with –m option.
E:\python37>python -m sysconfig Platform: "win-amd64" Python version: "3.7" Current installation scheme: "nt" Paths: data = "E:\python37" include = "E:\python37\Include" platinclude = "E:\python37\Include" platlib = "E:\python37\Lib\site-packages" platstdlib = "E:\python37\Lib" purelib = "E:\python37\Lib\site-packages" scripts = "E:\python37\Scripts" stdlib = "E:\python37\Lib" Variables: BINDIR = "E:\python37" BINLIBDEST = "E:\python37\Lib" EXE = ".exe" EXT_SUFFIX = ".pyd" INCLUDEPY = "E:\python37\Include" LIBDEST = "E:\python37\Lib" SO = ".pyd" VERSION = "37" abiflags = "" base = "E:\python37" exec_prefix = "E:\python37" installed_base = "E:\python37" installed_platbase = "E:\python37" platbase = "E:\python37" prefix = "E:\python37" projectbase = "E:\python37" py_version = "3.7.2" py_version_nodot = "37" py_version_short = "3.7" srcdir = "E:\python37" userbase = "C:\Users\acer\AppData\Roaming\Python"