Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Fails to same Python script from Terminal/Automator/Script Editor

Hi, I want to make a button on the menubar to run a Python script I made. To achieve that I thought to use Automator or Script Editor, but:

If I run the script on Terminal manually, all fine. (cd path/to/script && python3 myscript.py)

If I run exactly the same code in brackets using Automator shell function or Apple Script, they give me an error of a Python module not installed (but it's installed, I'm sure it is)

Any idea?

MacBook Pro 13″, macOS 11.4

Posted on Jun 13, 2021 8:05 AM

Reply
Question marked as Best reply

Posted on Jun 13, 2021 10:59 AM

You copy/paste the actual source code content of your script inside the Python HERE document right after the import statements. You don't select it to pass into the Run Shell Script action. You don't need that print statement that I used for the previous example.

Similar questions

9 replies

Jun 13, 2021 8:43 AM in response to ileonemil

When you run Python in an Automator Run Shell Script, or Run AppleScript action, it is running Python 2.7.16, the default Python installation on macOS, because it hasn't a clue where Python3 is installed.


In order to run Python3 in an Automator Run Shell Script action, you need to use HERE syntax like the following in a Bash or Zsh shell:


Jun 13, 2021 9:10 AM in response to ileonemil

You didn't follow the example exactly as your Passa a input: is set to come stdin, not as arguments. You will need to change that so you can pass the results from the previous action into your Python3 script code as sys.argv[1]. The only purpose of my example was to confirm the path to the Python3 (3.9.5) library.


What is the file that you have selected? Is it a Python module of some kind?

Fails to same Python script from Terminal/Automator/Script Editor

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.