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

What does GCC have to do with a 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.
>>> 

这次没有提到 clang。这是为什么?

CPython 解释器本身就是written in C。使用什么编译器将 C 代码转换为二进制可执行文件很重要;行为和性能可能存在细微差别,因此在横幅中有所提及。

您有两个不同的 Python 二进制文件,横幅中的差异反映了这些二进制文件的构建方式的差异。由于 Python 2.7 版本是与 OS X 捆绑在一起的版本,它是由 Apple 工程师使用不同的工具链构建的(使用 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.