I’ll preface this post with the caveat that both Python and all things Unix are new to me. I’ve been dabbling in some Raspberry Pi stuff and it is generally going well.
I’m having a nagging problem running a Python script from Shortcuts using the Run Script over SSH action that I can’t resolve.
The Python script I’m trying to run from Shortcuts executes fine when I run directly from the command line on the RPi. However, when I try to run the same script from Shortcuts, the script errors out with a “no module named gpizero” message.
I’m running a standard install of Raspbian Lite and Python 3. Everything is up to date. Let me know if there is other useful environmental info to help with troubleshooting.
I’ve exhausted my Googling and am going in circles. I would welcome any guidance from this group. Thanks in advance – jay
While you can add python3 to your path, why not specify it after the shebang (#!...) on the first line of your script? That way you don’t depend on python3 being in the path.
#!/usr/bin/python3
from gpiozero import LED
In case you, or another future reader, don’t know about the shebang: it tells the operating system which interpreter should be used to execute the script. Thus, when a valid shebang exists on the first line, if no other interpreter is supplied by the user, the interpreter in the shebang will be used.
In the example above with the file named foo (Note that the .py extension is unnecessary), first make the script executable
Hello, I am having the same issue that OP described but not able to solve it. I am using iOS shortcuts action run script over ssh but it says that module not found whereas I can run the same script without any issues directly on the raspberry pi. Any help is appreciated
Thank you
which command should i use to know that ?
edit: ran echo $PATH from shortcuts and also the raspberry pi and they show different directories; on the pi these directories are shown : /home/pi/.local/bin:/home/pi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
but from shortcuts only these are shown : /usr/local/bin:/usr/bin:/bin:/usr/games
Ok now got it to add the directories to path and checked with echo $PATH that they are added. But still having the same ModuleNotFoundError from shortcuts.
Check that you are signing in with the same user account in both options and that you can find the module on one of the PATH paths specified when you are signing in from Shortcuts.
if you have the module available and you have specified the appropriate oath as a place to look for it, then it should work.
Signing in with same user account. And yes the directory of the module is in the PATH variable when signing in with shortcuts (checked with echo $PATH).
you have specified the appropriate oath as a place to look for it