0

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

mac
  • 42,153
  • 26
  • 121
  • 131
Maurits
  • 2,082
  • 3
  • 28
  • 32

1 Answers1

2

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.

Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
  • That article makes it sound like copying environment variables to `~/.bashrc` will make eclipse see them. So I hard-linked `~/.bashrc` to `~/.bash_profile` and restarted eclipse. However, from a python script in eclipse, if I print out everything in `os.environ`, I don't see the environment variables defined in `~/.bashrc`. Are the instructions wrong or am I confused? – dhg Jul 19 '11 at 16:00
  • Thanks for the article. Setting /etc/bashrc or ~/.bashrc, however, is not working for me. Current fix is a platform dependent config file with the paths to the executables. – Maurits Jul 19 '11 at 16:03
  • So what's the best place to set the variables so that they are seen by things in the dock? – dhg Jul 19 '11 at 16:07
  • http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/588442#588442 or http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/3756686#3756686 – Peter Lyons Jul 20 '11 at 12:41