How to get the specific C compiler type from Python distutils?
<p>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.</p>

<p>I understand <code>distutils.ccompiler.get_default_compiler()</code> or something like <code>compiler.compiler_type</code> would return a compiler name. But it is too coarse just like "unix", etc.</p>

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

<p>One possible way to get the information is to check the system's environment variable <code>CC</code> via <code>os.environ["CC"]</code>, but it is not guaranteed that every system has <code>CC</code> defined so it is not a universal solution.</p>

<p>So, what should I do then? Thanks in advance! </p>

<p>Generally you should be able to use the <strong><a href="https://docs.python.org/2/library/platform.html#platform.python_compiler" rel="nofollow"><code>platform</code></a></strong> module to get the info:</p>

<pre><code>&gt;&gt;&gt; import platform
&gt;&gt;&gt; platform.python_compiler()
'GCC 4.8.5 20150623 (Red Hat 4.8.5-4)'
</code></pre>

python c