Python “no module named...” error when running SSH script from Shortcuts

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.

The beginning of the Python script is:

#!/usr/bin/python
from gpiozero import LED

The simple SSH action I’m using is:

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

Finally figured it out. Posting here in case others trip on the same…

I needed to provide the full path to Python in the script

/usr/bin/python3 onair.py

I suspect you’re not setting the path to Python 3 in the $PATH variable when you initiate the session.

Do a echo $PATH when you get a chance.

But your method would certainly work.

@Martin_Packer thanks for the tip. I assume that is the issue. This gives me more insight (and more things to learn). — jay

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

1 Like