14

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?

cs95
  • 379,657
  • 97
  • 704
  • 746
  • 7
    It’s whatever the Python interpreter was compiled with. – Ry- Jun 19 '17 at 13:52
  • @Ryan Oh, that was simpler than I thought. :0 Why does 2.7 mention both gcc and clang, while 3.6 mentions gcc only? – cs95 Jun 19 '17 at 13:53
  • 1
    @Coldspeed: You'd have to ask Apple about how they build Python then. – Martijn Pieters Jun 19 '17 at 13:54
  • Python is compiled still. Not like other languages which is to machine code ahead of time, but rather bytecode. Take a [look](https://stackoverflow.com/questions/6889747/is-python-interpreted-or-compiled-or-both). – pstatix Jun 19 '17 at 13:54
  • If you write a py code, you have to run it through an interpreter in order to make the code run. The interpreter itself is being developed in another language. The `GCC` is to indicate which compiler is used to create the python interpreter program. – KarelG Jun 19 '17 at 13:54
  • 2
    @Coldspeed: and OS X doesn't come with Python 3.6 by default, so you installed it from somewhere. Whomever bundled that latter installer, also may know how *they* configured the build. Different people may be using different toolchains. – Martijn Pieters Jun 19 '17 at 13:55
  • Yeah, the 2.6 and 2.7 are the system default versions. I downloaded 3.4, 3.5 and 3.6 with brew. Only the system defaults have clang, and that makes sense now. Will accept your answer when I can. Thanks. – cs95 Jun 19 '17 at 13:56

1 Answers1

16

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • If you don't mind me asking, is the source code for the interpreter openly available for perusal? Do you have a link I can look at? A quick search turns up nothing. – cs95 Jun 19 '17 at 13:58
  • 2
    @Coldspeed: yes, it is, Python is Open Source Software. Just download it from Python.org or look at the [GitHub repository](https://github.com/python/cpython). – Martijn Pieters Jun 19 '17 at 13:59