Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

cmake

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.

like image 313
rocksportrocker Avatar asked Dec 28 '25 02:12

rocksportrocker


2 Answers

Use platform.python_compiler().

like image 165
mouad Avatar answered Dec 30 '25 16:12

mouad


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

like image 41
mdeous Avatar answered Dec 30 '25 15:12

mdeous



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!