I believe that the main difference between running an application from macOS’s terminal and via clicking on it is that clicking on it runs the application in a very bare environment with almost no environment variables so that your application can’t find the home directory or the current encoding/locale and any application which it is supposed to find in $PATH will be invisible to it. I’m afraid the best I can offer for debugging is to wrap your code in something like the block below then inspect /tmp/error-message.txt to see what the problem really is.
import traceback
try:
# Your code here.
except BaseException as ex:
with open("/tmp/error-message.txt", "w") as f:
traceback.print_exc(file=f)
raise
If you find that that file never gets written, it’s probably macOS’s gatekeeper blocking your application from running.