Python, change current shell environment variables while using Popen?
<p>I have an XML that contains information about environment variable to set into the shell by my python script.  Here is a snippet of the XML :</p>

<pre><code>&lt;envVar name='QTDIR'&gt;/homeqt/libs.qt4/qt4.5.1&lt;/envVar&gt;
&lt;envVar name='MAKE'&gt;which make&lt;/envVar&gt;
</code></pre>

<p>This part of this snippet tells my python script to set environment variables QTDIR and MAKE.</p>

<p>My concern is the difference how i have to set the above variables.  I know that i can use os.environ to set environment variables and do something like this :</p>

<pre><code>os.environ['QTDIR'] = "/homeqt/libs.qt4/qt4.5.1"
</code></pre>

<p>But i can't use this to set my MAKE variable, i have to execute the command "<em>which make</em>" (to get the path of make executable).  My goal is to use the same method/function to set every variables.  </p>

<p>SO, i thought to do something like this:</p>

<pre><code>Popen("QTDIR=/homeqt/libs.qt4/qt4.5.1 ; export QTDIR", shell=True, stdout=PIPE, stderr=PIPE)
Popen("MAKE=which make ; export MAKE", shell=True, stdout=PIPE, stderr=PIPE)
</code></pre>

<p>But if i do this, the variable will be set only for the subprocess, not for the current shell.</p>

<p>So, my question is, is there a way to do what i want?  I DON'T want to analyse the XML and do something like this : </p>

<p>(pseudocode)</p>

<pre><code>if QTDIR has normal value
    os.environ['QTDIR'] = "/homeqt/libs.qt4/qt4.5.1"
if MAKE has value to be executed
    p = Popen("which make", shell=True, stdout=PIPE, stderr=PIPE)
    stdout, stderr = p.communicate()
    os.environ['MAKE'] = stdout
</code></pre>
