問題描述
您可以通過多種方式編譯 Python.我想知道我的 Python 是用哪些選項編譯的.
You can compile Python in various ways. I'd like to find out with which options my Python was compiled.
具體用例:我的 Python 是用 readline 編譯的嗎?我知道我可以通過import readline"看到這一點,但我想查看我的 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 可執(zhí)行文件,不是我自己編寫的源代碼.
I mean the Python executable and not source code written by myself.
推薦答案
有模塊可以查看系統(tǒng)配置
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')
也可以通過 shell 訪問:
It is also accessible via shell:
python3 -m sysconfig | less
python2.7之前必須使用
before python2.7, you have to use
import distutils.sysconfig
print distutils.sysconfig.get_config_vars()
這篇關(guān)于如何獲取 Python 編譯時使用的選項列表?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!