Running a python installer/builder within a python script in different folders
<p>I have a python code that links C code into Python that I want to run. This code is inside the folder <code>mymodule/foo</code> which contains two files: a <code>setup.py</code> file and a <code>foo.c</code> file. What you usually had to do is to enter the <code>mymodule/foo</code> folder, and do</p>

<pre><code>python setup.py build
</code></pre>

<p>This creates a .so file which you can then import in python. I have to do this for several sub-folders in the <code>mymodule</code> folder, so I wanted to do this automatically via an <code>os.system()</code> call. However, when I'm on the <code>mymodule</code> folder and do this:</p>

<pre><code>os.system('python foo/setup.py build')
</code></pre>

<p>I get </p>

<pre><code>gcc: error: foo.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.
error: command 'gcc' failed with exit status 4
</code></pre>

<p>Apparently the <code>setup.py</code> file is trying to find the <code>foo.c</code> code in <code>mymodule</code> folder and not on the <code>mymodule/foo</code> folder. So far, my solution has been to copy the <code>foo.c</code> file into the <code>mymodule</code> folder, run that line of code, and then remove the copy of the file from <code>mymodule</code> folder. I find this solution, however, messy. </p>

<p>Do you have any ideas on how to do this elegantly?</p>
