Access to Python’s configuration information

PythonServer Side ProgrammingProgramming

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


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':

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']


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')
>>> sysconfig.get_config_var('srcdir')

Python uses an installation scheme that differs depending on the platform and on the installation options. Following schemes are currently supported:

posix_prefixscheme for Posix platforms like Linux or Mac OS X.
posix_homescheme for Posix platforms used when a home option is used upon installation.
posix_userscheme for Posix platforms used when a component is installed through Distutils and the user option is used.
ntscheme for NT platforms like Windows.
nt_userscheme for NT platforms, when the user option is used


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:

stdlibdirectory containing the standard Python library files that are not platform-specific.
platstdlibdirectory containing the standard Python library files that are platform-specific.
platlibdirectory for site-specific, platform-specific files.
purelibdirectory for site-specific, non-platform-specific files.
includedirectory for non-platform-specific header files.
platincludedirectory for platform-specific header files.
scriptsdirectory for script files.
datadirectory for data files.


This function returns installation path corresponding to the path name, from the install scheme named scheme.

>>> sysconfig.get_path('include')

>>> sysconfig.get_platform()


This function returns the MAJOR.MINOR Python version number as a string.


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"
   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"
   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"
Published on 20-Feb-2019 11:49:34