title: Set Environmental Variables in Python with Popen
body: <p>I want to set an environmental variable in linux terminal through a python script. I seem to be able to set environmental variables when using <code>os.environ['BLASTDB'] = '/path/to/directory'</code> .</p>
  
  <p>However I was initially trying to set this variable with <code>subprocess.Popen</code> with no success.</p>
  
  <pre><code>import subprocess
  import shlex
  
  cmd1 = 'export BLASTDB=/path/to/directory'
  args = shlex.split(cmd1)
  p = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
  </code></pre>
  
  <p>Why does <code>subprocess.Popen</code> fail to set the environmental variable BLASTDB to '/path/to/directory'?</p>
  
  <p>NOTE:
  This also fails when using:</p>
  
  <pre><code>import os
  os.system('export BLASTDB=/path/to/directory')
  </code></pre>