Re: Environment variable issues running py2app application

Ned Deily <[email protected]>
Newsgroups gmane.comp.python.apple
Message-ID <[email protected]>
In article 
<CACgdh2jujjuvueKOXpr2e4utJe3ZdYad8OX9JCFFpLhgHbXAKA@mail.gmail.com>,
 Paul Wiseman <[email protected]> wrote:
> I've never seen this problem before but one user seems to be experiencing
> this issue and I'm at a bit of a loss as to what the cause could be
> 
> One part of the app runs this: subprocess.Popen(['/usr/bin/env',
> 'system_profiler', 'SPUSBDataType', '-xml'])
> 
> I've never seen a problem running this, however in one users logs it's
> returning: env: system_profiler: No such file or directory
> 
> So I thought that maybe their PATH variable doesn't include path to the
> binary, I asked them to provide the output of '/usr/bin/env' and 'which
> system_profiler'
> 
> 'which system profiler' returned '/usr/sbin/system_profiler' and
> '/usr/sbin' was in their PATH variable that returned from /usr/bin/env, so
> I don't really get what's going on.
> 
> This also looks like it only happens if the user opens the .app directly,
> but if they open the binary directly in the .app/Contents/MacOS/ folder, it
> works and it can find these external binaries through subprocess.
> 
> I'm really not sure what might be causing this? and I've never experienced
> it myself when testing, nor has it ever been reported before which makes me
> inclined to believe it's some external setting / config on the users
> machine which is causing this behaviour?

Normally, a shell (like bash) is not involved in launching an OS X app 
bundle, like those produced by py2app, so the environment variables seen 
in an app's environment are not the same as what is seen from a terminal 
shell session.  Thus, the output of `which` and of the user's shell 
$PATH aren't relevant.   It used to be possible to influence to the 
user's GUI environment by supplying a ~/.MacOSX/environment.plist but I 
believe that is no longer supported on current OS X releases and, in any 
case, it's a bad idea to depend on it.  It is possible to include 
app-specific environment variables in the app's plist.  But, in your 
case, the simplest thing to do is use an absolute path to 
`system_profiler` and avoid use of `/usr/bin/env` within an app bundle.

-- 
 Ned Deily,
 [email protected]

_______________________________________________
Pythonmac-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.