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 distutils.ccompiler.get_default_compiler()
or something like compiler.compiler_type
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 CC
via os.environ["CC"]
, but it is not guaranteed that every system has CC
defined so it is not a universal solution.
So, what should I do then? Thanks in advance!
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)'
You can use distutils
to get the actual c compiler and read its properties
from distutils.ccompiler import new_compiler
from distutils.sysconfig import customize_compiler
ccompiler = new_compiler()
customize_compiler(ccompiler)
path_to_compiler = ccompiler.compiler[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With