rocksportrocker
rocksportrocker

Reputation: 7419

Looking for method / module to determine the compiler which was used for building the CPython interpreter

When I start the Python interpreter in command line mode I get a message saying which compiler was used for building it. Is there a way to get this information in Python ? I know I could start the interpreter with subprocess.Popen and parse the output, but I'm looking for an easier and more elegant method.

The background is that I want to build Python extensions for a CMake based C++ framework, and I would like to write a CMake macro wich checks if the correct compiler is installed.

Upvotes: 3

Views: 155

Answers (2)

mdeous
mdeous

Reputation: 18049

You can use the sys.version variable to access this information:

>>> sys.version
'2.7.2 (default, Jun 29 2011, 11:17:09) \n[GCC 4.6.1]'

It will tell you which compiler was used to compile Python, but it won't ensure the mentioned compiler is installed on the system (this could be a pre-built Python version).

Upvotes: 3

mouad
mouad

Reputation: 70059

Use platform.python_compiler().

Upvotes: 6

Related Questions