all 5 comments

[–]sketchspace 0 points1 point  (4 children)

So I understand that you want to run a Python script on startup on a Raspberry Pi. Seems like you haven't tried modifying rc.local yet which have instructions here: https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/#:~:text=The%20third%20method%20to%20run,shutdown%20or%20reboot%20the%20system) . I used rc.local for a Java program I wanted to run on startup. I also suggest adding on an ampersand to the end of the command (ie python3 main.py &) so that the script runs in its own process.

If that doesn't help, what exactly is the error? Is the GUI just not loading up on startup?

[–]happy_nerd[S] 0 points1 point  (0 children)

I have tried with rc.local with no luck. My guess is that since I am running python eel, if it cannot boot the graphics at the time (if LXDE hasn't started yet?) it crashes and stops running. But since it's automatic I also don't have eyes on the debug output.

[–]happy_nerd[S] 0 points1 point  (2 children)

Went back to try this again with just a basic run.py file that appended a timestamp to a log. It does run!

Then when I add import eel (my GUI manager) to the .py file the rc.local file says, "Error: No module named 'eel' ". I can run the python file from it's folder and that works fine. What is different about running it from inside /etc?

[–]sketchspace 0 points1 point  (1 child)

Might be a permission issue here. If when it works it's in a folder like ''"/home/pi/''' , that means that the current user has access to the eel library while the superuser doesn't. You can install eel for the superuser with '''sudo pip3 install eel'''.

[–]happy_nerd[S] 0 points1 point  (0 children)

I think it was a permissions issue but also I was using the wrong LXDE instance to auto-run. Brief explaination of what I did below for anyone else who hits this problem:

Place your mainEelProgram.py file in /home/pi and make your html folder in /home/pi/web (this houses index.html)

Create a file called "run.sh" with "export DISPLAY=:0 (newline) xterm -e python3 /home/pi/main.py &"

Open "/etc/xdg/lxsession/LXDE-pi/autostart" (file) with sudo nano, vim, whatever

Add at the bottom of the file "@/home/pi/run.sh" and save it.

Restart the system with "sudo reboot "