The easiest way to get the include path is to use the sysconfig.get_path()
function:
import sysconfig
include_path = sysconfig.get_path('include')
This path is adjusted for virtualenvs already. For scripting purposes outside of Python, you can either print the path directly:
$ python -c 'import sysconfig; print(sysconfig.get_path("include"))'
or get all sysconfig
data by running the module as a script:
$ python -m sysconfig
then parse the output that dumps to stdout.
Other than that, if you only want the executable name (with the m
included), you can get that from the sys.executable
variable; this includes the m
suffix:
>>> import sys
>>> sys.executable
'/usr/bin/python3.5m'
As of Python 3.2, you can also use the sys.abiflags
variable; it is set to m
in this case:
>>> sys.abiflags
'm'
Also see PEP 3149.
For earlier Python versions, the various flags that influence the suffixes are available still via the aforementioned sysconfig
module as configuration variables:
pymalloc = bool(sysconfig.get_config_var('WITH_PYMALLOC'))
pydebug = bool(sysconfig.get_config_var('WITH_PYDEBUG'))
wideunicode = bool(sysconfig.get_config_var('WITH_WIDE_UNICODE'))
Note that ubuntu merely compiles multiple binaries and adjusts the executable name to reflect the configuration option chosen; on other systems the ABI flags are not necessarily reflected in the executable name.