GCC与python解释器有什么关系?

时间:2017-06-19 13:51:25

标签: python interpreter

我刚在macintosh上发现了这一点。运行$ python会使用以下行触发解释器会话:

$ python2.7
Python 2.7.10 (default, Feb  6 2017, 23:53:20) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

启动文本的第二行提到了GCC和clang版本。

这两个如何与python解释器相关?鉴于python是一种解释型语言,根本不应该有编译器的低语,所以我很好奇为什么会显示它。

现在这与python3.6相同:

$ python3.6
Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

这次没有提到铿锵声。为什么?

1 个答案:

答案 0 :(得分:8)

The CPython interpreter is itself written in C. It matters what compiler was used to convert the C code into a binary executable; behaviour and performance can differ in subtle ways, so it is mentioned in the banner.

You have two different Python binaries, the differences in the banner reflect differences in how those binaries where built. Since the Python 2.7 release is the one that comes bundled with OS X, it was built by Apple engineers using a different toolchain (using the clang compiler) from the Python 3.6 installation, which you must have installed separately (OS X doesn't include Python 3.6 yet). The latter was compiled with the GCC compiler.