Can't Execute a Python File

if which python3 does not return the python path, it means your zsh does not know where it is, which means, either you do not have python3 installed or python3 is not in the environ path directory.

If you do have python3 installed, you will have to find out where it is and add its path to the environ path variable. Where python3 is depends on how we install it.
For instance, homebrew installs packages under the /usr/local/Cellar/ directory. For python3, it will be something like /usr/local/Cellar/python@3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/bin/python3.9.

A convenient way to find out the installed python versions is to use the applescript library window (I discovered it accidentally). For instance, I have four python versions installed, one came with MacOS (2.7), one came with Xcode (3.8.9), and two were installed with homebrew (3.9 and 3.10).

homebrew also creates symlinks for packages in the /usr/local/bin folder (it's more complicated and I still need to learn more. for more info., see, e.g., this post). Therefore, we don't need to reference to the full path /usr/local/Cellar/python@3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/bin/python3.9; we may use /usr/local/bin/python3 instead.

If we open the Get info window of /usr/local/bin/python3, we can see it points to the original location.

img_shadow_soft

Besides symlinks, there is also alias. For instance, when I run which python on my Mac, it returns

which python
python: aliased to /usr/local/bin/python3

As I just mentioned, /usr/local/bin/python3 is a symlink pointing to /usr/local/Cellar/python@3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/bin/python3.9.

Enough has been said. It took me a while to gradually understand these things. I hope you are not confused.

i dosent work

i want to ask if you know other tool for mac
that executive script or file with hot key

Can create a 'quick action' in Automate using an AppleScript to tell Terminal to do something like:

tell application "Terminal" to do script "python myscript.py"

What doesn't work?

I was trying my best to explain where to find python is installed and how to set them up in your environment path. Maybe I did not say clearly enough.

Can you do a simply thing?

  1. Open Script Editor.app
  2. Go to FileOpen Dictionary...
  3. Look for Python.app and take a screenshot of all of them and post here.

It looks like this:

Hey Daniel,

Yes, you can tell the Terminal to run a script with AppleScript – and Keyboard Maestro can run the AppleScript.

See this post:

"Insert text by typing" doesn't work in the Terminal - #4 by ccstone

-Chris

It not Execute the script
It just open the Terminal

The script is this : username =input("What is your name?")
print(username)

Screen Shot 2021-10-26 at 0.32.51

i want to do whet the you suggest
but with all path , not with name of the python file
like this :/Users/guyatia/PycharmProjects/guy6666/main.py

Hey Daniel,

That's no surprise. You apparently didn't read or didn't understand the post I pointed you to.

--------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2021/10/25 16:52
# dMod: 2021/10/25 16:52
# Appl: Terminal
# Task: Run a Python Script (on disk) in the Active Tab of the Front Window.
#     : Open a new window if active tab is busy.
# Libs: None
# Osax: None 
# Tags: @Applescript, @Terminal, @Python, @Run, @Script
--------------------------------------------------------

set shCmdStr to text 2 thru -2 of "
python3 ~/'test_directory/Python_Test/python_test_02.py'
"

try
   
   tell application "Terminal"
      if (busy of front window) = true then
         
         # Opens a new window if needed.
         do script shCmdStr
         
      else if (busy of front window) = false then
         
         # Runs in the active tab of the front window
         tell front window
            do script shCmdStr in selected tab
         end tell
         
      end if
   end tell
   
on error eMsg number eNum
   tell me to display dialog eMsg & return & return & eNum
end try

--------------------------------------------------------

Your big problem is that you're trying to do something ==interactive== that requires an actual Terminal and not a script-runner mechanism like Keyboard Maestro provides.

Keyboard Maestro cannot (and likely will never be able to) do this:

#!/usr/bin/env python
username =input("What is your name?")
print(username)

On the other hand – Keyboard Maestro can do this:

#!/usr/bin/env python
str_a = ("Displaying string variable")
print (str_a)

Since we're simply outputting a string.

-Chris

i wish i could pay you or somebody
to explained and to show me how to do that

this is so hard from me
obstetrical after obstetrical

Finally its working.
I am using python launcher.