How to get the list of options that Python was compiled with?
And another way to do it... Python supplies scripts per installed version...
ls -l /usr/bin/python*config*
16 Dec 21 2013 /usr/bin/python-config -> python2.7-config
16 Dec 21 2013 /usr/bin/python2-config -> python2.7-config
33 Mar 22 18:57 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
16 Mar 23 03:17 /usr/bin/python3-config -> python3.4-config
33 Apr 11 09:15 /usr/bin/python3.4-config -> x86_64-linux-gnu-python3.4-config
34 Apr 11 09:15 /usr/bin/python3.4m-config -> x86_64-linux-gnu-python3.4m-config
17 Mar 23 03:17 /usr/bin/python3m-config -> python3.4m-config
python3-config --help
Usage: /usr/bin/python3-config --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir
python3-config --prefix
/usr
The answers from one of my systems are:
--prefix /usr
--exec-prefix /usr
--includes -I/usr/include/python3.4m -I/usr/include/python3.4m
--libs -lpthread -ldl -lutil -lm -lpython3.4m
--cflags -I/usr/include/python3.4m -I/usr/include/python3.4m -Wno-unused-result -Werror=declaration-after-statement -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
--ldflags -L/usr/lib/python3.4/config-3.4m-x86_64-linux-gnu -L/usr/lib -lpthread -ldl -lutil -lm -lpython3.4m -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions
--extension-suffix @SO@
--abiflags m
--configdir /usr/lib/python3.4/config-3.4m-x86_64-linux-gnu
So if you need setting values for bash scripts and such, these are available with this command line utility.
To build on mirk's answer, to find the configure flags that were actually used during the build, the value you're looking for is CONFIG_ARGS
.
For example, this is the output for an Ubuntu-compiled Python:
>>> print distutils.sysconfig.get_config_var('CONFIG_ARGS')
'--enable-shared' '--prefix=/usr' '--enable-ipv6'
'--enable-unicode=ucs4' '--with-dbmliborder=bdb:gdbm'
'--with-system-expat' '--with-system-ffi' '--with-fpe ctl'
'CC=x86_64-linux-gnu-gcc' 'CFLAGS=-D_FORTIFY_SOURCE=2 -g
-fstack-protector --param=ssp-buffer-size=4 -Wformat
-Werror=format-security ' 'LDFLAGS=-Wl,-Bs ymbolic-functions
-Wl,-z,relro'
There is a module to see the system config
import sysconfig
print(sysconfig.get_config_vars())
It offers an interface to get individual variables as well.
sysconfig.get_config_var('HAVE_LIBREADLINE')
It is also accessible via shell:
python3 -m sysconfig | less
Edit:
before python2.7, you have to use
import distutils.sysconfig
print distutils.sysconfig.get_config_vars()