title: PATH environment variable in python
body: <p>I'm using OS X 10.8.3.</p>
  
  <p>If you open a terminal, </p>
  
  <pre><code>echo $PATH
  </code></pre>
  
  <p>/usr/local/bin is there, also if you run it via sh or bash</p>
  
  <p>however the python code output of:</p>
  
  <pre><code>import os
  print os.environ.copy()
  </code></pre>
  
  <p>lacks the /usr/local/bin path</p>
  
  <p>Can anyone explain how $PATH works? is there something that extends it? why did the python script didn't print the $PATH I see in the terminal? Does it behave the same on linux distributions?</p>
  
  <p>How did I encountered it? I installed a sublime 2 plugin, js2coffee, the plugin runs a subprocess (import subprocess), providing the name of an exec, js2coffee - which was in the /usr/local/bin, a path that wasn't in the python os env. In order to fix it I had to add it to the env:</p>
  
  <pre><code>env = os.environ.copy()
  env["PATH"] = "/usr/local/bin/"
  
  js2coffee = subprocess.Popen(
      'js2coffee',
      stdin=subprocess.PIPE,
      stdout=subprocess.PIPE,
      stderr=subprocess.PIPE,
      shell=True,
      env= env
  )
  </code></pre>