I'm using OS X 10.8.3.
If you open a terminal,
echo $PATH
/usr/local/bin is there, also if you run it via sh or bash
however the python code output of:
import os
print os.environ.copy()
lacks the /usr/local/bin path
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?
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:
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
)