is there a way to compile a c/c++ program from python?

Currently I'm coding a python script to compile a C/C++ Linux kernel in the following way:

subprocess.check_call(["make", "-j5"])
subprocess.check_call(["make", "-j5", "modules_install"])
subprocess.check_call(["make", "-j5", "install"])

With these approach the commands are executed in the shell. So I was wondering if there is another way to compile the kernel using python build in libraries?


Ultimately, python isn't a C/C++ compiler, so you need to ship out the compiling to an external program (e.g. gcc). So, there is no way to do this entirely in python.

Note that here python doesn't spawn any shells (although make might). You could try to reproduce what make does entirely in python, (there is a version of make written in python FWIW), but honestly, it's not worth it. You need to spawn subprocesses anyway -- you might as well use the tools which are already in place and "tried and true".

Need Your Help

THREE JS 3ds Max Gradients not applied

webgl three.js 3dsmax

I exported my 3d model from 3ds Max as json using threejsexporter ( and as .obj (which I then converted to json us...

Spark's will not execute unless the item inside RDD is visited

scala apache-spark

I'm not quite sure about how Scala and Spark works, maybe I write the code in the wrong way.