SD does not see applications in user path

I’m new to SD and am noticing some odd behavior relating to shell scripts running programs on the user path.

I have installed Python3 using brew:

paul-> which python3
/usr/local/bin/python3
paul-> python3 -V
Python 3.7.6

I have created a Python 3 program that I am calling via an AppleScript. Here is I very simplified version

log (do shell script "python3 -V")

This runs just fine from the command line

paul-> osascript ~/Desktop/python.scpt 
Python 3.7.6

When I run the script via SD, SD reports a failure

Error: sh: python3: command not found (127)

Is there something I need to do to make Python visible to SD?

I suspect your issue is not related to Script Debugger but to the do shell script command, and the environment it runs in. See this for details, particularly the section ‘Why doesn’t do shell script work exactly like Terminal?’:

https://developer.apple.com/library/archive/technotes/tn2065/_index.html

I see the argument, @ShaneStanley, but why does this work?

paul-> osascript ~/Desktop/python.scpt 
Python 3.7.6

Hard to tell without knowing what the file contains. It certainly doesn’t contain what you posted above, because the log command doesn’t return any result.

Have you tried just passing the full path to do shell script?

@ShaneStanley it does indeed contain just this simple line. See the screenshot below.

Your suggestion did get me thinking though. I hadn’t noticed before, but the SD message said that sh could not find python3. I changed the call to
log (do shell script "/usr/local/bin/python3 -V") and SD reported (*Python 3.7.6*) in the log viewer!

Apparently when running from the bash command line, osascript inherits the bash environment vars. So, the question is why does SD not use the user-preferred shell (along with its defined environment vars)?

Because that would be providing a way for people to write applets that work in SD but fail as soon as they saved them as applets, or ran then from any other app. From a portability perspective, it would be a disaster. Scripts run via osascript are the exception rather than the rule.

I see, @ShaneStanley. Thanks for the explanation!