YDW YDW - 1 year ago 63
Python Question

How to get the specific C compiler type from Python distutils?

I'd like to check the system's C compiler in Python so that I can add library links accordingly to compile my Cython code.

I understand

or something like
would return a compiler name. But it is too coarse just like "unix", etc.

What I need is more specific information such as "gcc", "icc", "clang", etc., which are all shown as "unix" using the methods above.

One possible way to get the information is to check the system's environment variable
, but it is not guaranteed that every system has
defined so it is not a universal solution.

So, what should I do then? Thanks in advance!

Answer Source

Generally you should be able to use the platform module to get the info:

>>> import platform
>>> platform.python_compiler()
'GCC 4.8.5 20150623 (Red Hat 4.8.5-4)'