Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does GCC have to do with a python interpreter?

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?

like image 724
cs95 Avatar asked Jun 19 '17 13:06

cs95


People also ask

What is GCC for Python?

In theory the plugin allows you to write Python scripts that can run inside GCC as it compiles code, exposing GCC's internal data structures as a collection of Python classes and functions. The bulk of the document describes the Python API it exposes.

Does Python require GCC?

Before installing Python, you'll need to install GCC. GCC can be obtained by downloading Xcode, the smaller Command Line Tools (must have an Apple account) or the even smaller OSX-GCC-Installer package. If you already have Xcode installed, do not install OSX-GCC-Installer.

What is the role of Python interpreter?

The interpreter operates somewhat like the Unix shell: when called with standard input connected to a tty device, it reads and executes commands interactively; when called with a file name argument or with a file as standard input, it reads and executes a script from that file.

Does Python use compiler or interpreter?

Python is an interpreted language, which means the source code of a Python program is converted into bytecode that is then executed by the Python virtual machine. Python is different from major compiled languages, such as C and C + +, as Python code is not required to be built and linked like code for these languages.


1 Answers

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.

like image 83
Martijn Pieters Avatar answered Oct 03 '22 10:10

Martijn Pieters