Skip to content
Advertisement

Python script not able to find package when executed from terminal at bootup, what am I doing wrong? [Raspbian]

sorry in case this is obvious or redundant, I’ve been looking around on this site for an answer to this problem but I couldn’t find anything that would fix it

What I am trying to achieve is executing a Python script when my raspberry pi turns on (after the desktop loads in)

I’ve been trying to do so by adding these lines at the end of /home/pi/.bashrc

echo Running at boot

sudo /usr/bin/python3.7m  /home/pi/Desktop/Program/NameOfTheProgram.py

The problem, as you might’ve guessed from the title, is that when the script is executed as I open the terminal, and consequently at bootup, python doesn’t appear to be capable of finding a package

    from SSIM_PIL import compare_ssim as ssim #Import ssim from ssim package
ModuleNotFoundError: No module named 'SSIM_PIL'

This problem does not arise when I execute the script from the terminal by using

/usr/bin/python3.7m  /home/pi/Desktop/Program/NameOfTheProgram.py

in which case the program is executed as intended, so my only guess is that this shouldn’t be a problem with the python version I’m using, since I’m 100% sure it’s the same one and it apparently should work, but I may be mistaken

I’ve also tried to put those same lines of code in /etc/rc.local, but to no avail

Am I missing something? Thank you in advance

Advertisement

Answer

It is me again, like Roberto pointed out removing sudo from the command did indeed work to execute the program when a terminal window is opened

Unfortunately this didn’t initiate the program at startup, but in theory all I need to do now is find a way to open a terminal window with a terminal command, and the program should be working correctly

This is admittedly a bit contrived, but it’s good enough as long as the program works

To open the terminal on boot I’ve edited the autostart file in the lxsession folder by adding @lxterminal to it, as illustrated in this answer

I’m answering to my own question as I don’t know how to mark a comment as “answer”, if that’s even possible

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement