On this page
sysconfig
Prev: sys | Up: stdlib_module | Next: syslog
Rel: sys, builtins, warnings, dataclasses, contextlib
Ref: docs.python.org — sysconfig
Tags: #public #python3 #stdlib
Import
import sysconfig
Overview
Exposes CPython's build-time and installation-layout configuration (get_paths, get_path, get_platform, get_config_var, get_python_version). Essential for packaging tools, virtual environment builders, and C-extension compilers that need portable purelib, platlib, scripts, and include directory locations.
Quick Start
import sysconfig
paths = sysconfig.get_paths()
assert "purelib" in paths and "scripts" in paths
assert isinstance(sysconfig.get_platform(), str)
Implementation Walkthrough
1. Querying Installation Paths & Build Flags Portably
import sysconfig
site_packages = sysconfig.get_path("purelib")
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
is_free_threaded = bool(sysconfig.get_config_var("Py_GIL_DISABLED"))
assert isinstance(site_packages, str)
Gotchas & Boundaries
- Prefer
sysconfig.get_paths()over hardcodinglib/python3.X/site-packages: Paths differ across Windows (Lib\site-packages), macOS framework builds, and Debian/Ubuntudist-packages. get_config_var(name)returnsNonewhen a variable is unset: Check forNonebefore formatting or splitting.- Replaces legacy
distutils.sysconfig(removed in Python 3.12).
Common Functions
- sysconfig.get_config_h_filename() —
get_config_h_filename()— Return the path of pyconfig.h. - sysconfig.get_config_var() —
get_config_var(name)— Return the value of a single variable using the dictionary returned by 'get_config_vars()'. - sysconfig.get_config_vars() —
get_config_vars(*args)— With no arguments, return a dictionary of all configuration variables relevant for the current platform. - sysconfig.get_makefile_filename() —
get_makefile_filename()— Return the path of the Makefile. - sysconfig.get_path() —
get_path(name, scheme='osx_framework_library', vars=None, expand=True)— Return a path corresponding to the scheme. - sysconfig.get_path_names() —
get_path_names()— Return a tuple containing the paths names. - sysconfig.get_paths() —
get_paths(scheme='osx_framework_library', vars=None, expand=True)— Return a mapping containing an install scheme. - sysconfig.get_platform() —
get_platform()— Return a string that identifies the current platform. - sysconfig.get_python_version() —
get_python_version()—sysconfig.get_python_version()function. - sysconfig.get_scheme_names() —
get_scheme_names()— Return a tuple containing the schemes names. - sysconfig.parse_config_h() —
parse_config_h(fp, vars=None)— Parse a config.h-style file.
Linked from
- tuts/python3/stdlib_module
- tuts/python3/stdlib_module/abc
- tuts/python3/stdlib_module/antigravity
- tuts/python3/stdlib_module/ast
- tuts/python3/stdlib_module/atexit
- tuts/python3/stdlib_module/builtins
- tuts/python3/stdlib_module/code
- tuts/python3/stdlib_module/codeop
- tuts/python3/stdlib_module/compileall
- tuts/python3/stdlib_module/contextlib
- tuts/python3/stdlib_module/dataclasses
- tuts/python3/stdlib_module/dis
- tuts/python3/stdlib_module/ensurepip
- tuts/python3/stdlib_module/gc
- tuts/python3/stdlib_module/importlib
- tuts/python3/stdlib_module/inspect
- tuts/python3/stdlib_module/keyword
- tuts/python3/stdlib_module/modulefinder
- tuts/python3/stdlib_module/opcode
- tuts/python3/stdlib_module/pickletools
- tuts/python3/stdlib_module/pkgutil
- tuts/python3/stdlib_module/py_compile
- tuts/python3/stdlib_module/pyclbr
- tuts/python3/stdlib_module/pyexpat
- tuts/python3/stdlib_module/runpy
- tuts/python3/stdlib_module/site
- tuts/python3/stdlib_module/sre_compile
- tuts/python3/stdlib_module/sre_constants
- tuts/python3/stdlib_module/sre_parse
- tuts/python3/stdlib_module/stdlib_module
- tuts/python3/stdlib_module/symtable
- tuts/python3/stdlib_module/sys
- tuts/python3/stdlib_module/sysconfig/get_config_h_filename
- tuts/python3/stdlib_module/sysconfig/get_config_var
- tuts/python3/stdlib_module/sysconfig/get_config_vars
- tuts/python3/stdlib_module/sysconfig/get_makefile_filename
- tuts/python3/stdlib_module/sysconfig/get_path
- tuts/python3/stdlib_module/sysconfig/get_path_names
- tuts/python3/stdlib_module/sysconfig/get_paths
- tuts/python3/stdlib_module/sysconfig/get_platform
- tuts/python3/stdlib_module/sysconfig/get_python_version
- tuts/python3/stdlib_module/sysconfig/get_scheme_names
- tuts/python3/stdlib_module/sysconfig/parse_config_h
- tuts/python3/stdlib_module/syslog
- tuts/python3/stdlib_module/tabnanny
- tuts/python3/stdlib_module/this
- tuts/python3/stdlib_module/token
- tuts/python3/stdlib_module/tokenize
- tuts/python3/stdlib_module/traceback
- tuts/python3/stdlib_module/venv
- tuts/python3/stdlib_module/warnings
- tuts/python3/stdlib_module/zipapp
- tuts/python3/stdlib_module/zipimport
- tuts/python3/tutorials/intermediate_python_and_software_engineering/modules_packages_and_tooling
Related notes
- tuts/python3/stdlib_module/builtins Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/contextlib Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/dataclasses Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/stdlib_module Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sys Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sysconfig/get_config_h_filename Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sysconfig/get_config_var Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sysconfig/get_config_vars Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sysconfig/get_makefile_filename Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sysconfig/get_path Linked here; links to this page; shared tags: #stdlib