you should see the full installation path. Perhaps, for example something like:
/usr/local/bin/python3
Whatever the full path is, use it in your Execute Shell Script action, instead of just writing python3
(Execute a Shell Script actions launch a vanilla shell, which doesn't automatically receive any search paths from the Terminal.app instance of the shell)
can you tell me in which way i know if
the which command shows that your python3 is installed at:/usr/local/bin/python3
what code in need to write in the terminal for this
the terminal say :
Python 3.9.7 (v3.9.7:1016ef3790, Aug 30 2021, 16:39:15)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information."
Funaho:test_directory myUser$ which python3
/opt/local/bin/python3
Alternatively you can use:
type python3
Funaho:test_directory myUser$ type python3
python3 is /opt/local/bin/python3
The path returned shows the location of the python3 executable.
To execute your python program use the following format with YOUR paths:
/opt/local/bin/python3 <path to your python file>
NOTE – if your python program is has dependencies on python 3 modules it's probably not going to work and will require some more configuration of your system.
I knew nothing about environ path when I started to learn programming languages. It took me a long time to understand the environ path.
I'll try to describe how I understand it.
When we use a command in the terminal, say python3 /path/to/file.py. On the mac, if the default language is zsh, zsh has to know where python3 (called interpreter) is and asks it to execute the scripts.
When we run which python3, if python3 is installed and zsh knows where it is, the which python3 command will return the path to python3, something like /usr/local/bin/python3.
If python3 is installed but zsh does not know it, then you will have to know where does zsh searches for python3. Here, environ path comes in.
If we run echo $PATH in the terminal, we will get a serial of directories separated by :. zsh search search these directories, looking for python3, if it finds it, then it will ask python3 to run the script. (if you have multiple python3 interpreters, the first that is found will be used as the interpreter. Therefore, the order of the directories matters). Otherwise, it will say that the interpreter is lacking. We will have to add the path to python3 to it by editing a file named .zshrc (for zsh).
When we run python scripts in Keyboard Maestro, we are not in the Terminal anymore. Therefore, the .zshrc file is irrelevant. We have to let Keyboard Maestro know where the python3 interpreter is. We do this by creating a Keyboard Maestro variable called ENV_PATH. Keyboard Maestro will search through these directories and look for python3.
If the ENV_PATH is properly set, we can use
python3 /path/to/file.py
in the Shell Script action to run the script.
If the ENV_PATH is not set, we have to use the full path to python3 instead of python3, that is, we have to use something like: