GCC与python解释器有什么关系

GCC与python解释器有什么关系

本文介绍了GCC与python解释器有什么关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在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解释器本身是用C语言编写的.重要的是使用什么编译器将C代码转换为二进制可执行文件.行为和性能可能会在微妙的方面有所不同,因此在标语中已提到.

您有两个不同的Python二进制文件,横幅中的差异反映了这些二进制文件的构建方式的差异.由于Python 2.7版本是OS X随附的版本,因此它是由Apple工程师使用不同的工具链(使用 clang编译器)(必须单独安装)(OS X还不包括Python 3.6).后者是使用 GCC编译器进行编译的.

I just noticed this on my macintosh. Running $ python fires up an interpreter session with the following lines:

$ 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.
>>>

The second line of the starting up text mentions GCC and clang versions.

How are these two related to the python interpreter? Given that python is an interpreted language, there should be no whisper of a compiler at all, so I was curious as to why this is shown.

Now here's the same thing with 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.
>>>

This time there's no mention of clang. Why's that?

解决方案

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.

这篇关于GCC与python解释器有什么关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 16:22