如何获取Python编译的选项列表?

时间:2021-12-07 13:11:14

You can compile Python in various ways. I'd like to find out with which options my Python was compiled.

您可以通过各种方式编译Python。我想知道我的Python编译的选项。

Concrete use-case: was my Python compiled with readline? I know I can see this by doing "import readline", but I'd like to see a list of compilation setting for my Python binary.

具体的用例:我的Python是用readline编译的吗?我知道我可以通过“import readline”来看到这一点,但是我希望看到我的Python二进制文件的编译设置列表。

Edit: I mean the Python executable and not source code written by myself.

编辑:我的意思是Python可执行文件,而不是我自己编写的源代码。

4 个解决方案

#1


47  

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

Edit:

编辑:

before python2.7, you have to use

在python2.7之前,你必须使用

import distutils.sysconfig
print distutils.sysconfig.get_config_vars()

#2


22  

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.

要构建mirk的答案,要找到构建期间实际使用的配置标志,您要查找的值是CONFIG_ARGS。

For example, this is the output for an Ubuntu-compiled Python:

例如,这是Ubuntu编译的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'

#3


8  

And another way to do it... Python supplies scripts per installed version...

另一种方法... Python为每个已安装的版本提供脚本...

  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.

因此,如果您需要为bash脚本等设置值,则可以使用此命令行实用程序。

#4


-1  

To get the list of options that PyPy was compiled with, run

要获取PyPy编译的选项列表,请运行

pypy --info

#1


47  

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

Edit:

编辑:

before python2.7, you have to use

在python2.7之前,你必须使用

import distutils.sysconfig
print distutils.sysconfig.get_config_vars()

#2


22  

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.

要构建mirk的答案,要找到构建期间实际使用的配置标志,您要查找的值是CONFIG_ARGS。

For example, this is the output for an Ubuntu-compiled Python:

例如,这是Ubuntu编译的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'

#3


8  

And another way to do it... Python supplies scripts per installed version...

另一种方法... Python为每个已安装的版本提供脚本...

  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.

因此,如果您需要为bash脚本等设置值,则可以使用此命令行实用程序。

#4


-1  

To get the list of options that PyPy was compiled with, run

要获取PyPy编译的选项列表,请运行

pypy --info