Maurits
Maurits

Reputation: 2114

Path environment variables in Python and Mac OS X when using subprocess.call

Python (2.6.6 -- EPD 6.3-1 (32-bit)) can not find a binary executable when using

call(cmmd, shell=True)

On Mac OS 10.6.8, started from Eclipse/Pydev, and returns that sh could not find the executable. Running

print os.environ['PATH']

returns the default paths:

/usr/bin:/bin:/usr/sbin:/sbin

Now, running this executable or the script for that matter from any shell is not a problem and its path is added in /etc/profile, ~/.profile and in /etc/paths

Any ideas on how to configure Pydev? The run configuration seems in order, i.e. it picks up the correct python version.

Note:edited for clarity

Upvotes: 0

Views: 3550

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 146174

There is a difference between a login shell and a non-login shell. When run by python launched from Eclipse, your shell will start as a non-login shell, which will NOT load the ~/.profile. This article has the details. So you need to make sure os.environ has the directory where your executable lives in it before you call subprocess.call or you can just give an absolute path to the executable, or make sure your shell script (if your executable is just a shell script) uses absolute paths or manages its own PATH environment variable. You can also pass a dictionary of environment variables to subprocess.Popen to get detailed control of the subprocess's environment and many other aspects.

Upvotes: 2

Related Questions