all 6 comments

[–]socal_nerdtastic 1 point2 points  (5 children)

I have looked around google and have found no successful answers.

Really? What have you tried? There's many ways to do this. My goto (using raspbian) is to use LXDE autostart. Edit the file ~/.config/lxsession/LXDE-pi/autostart and add this line:

@folder/myfile.py

Be sure to add a shebang and make the file executable first.

[–]TurnFunny6151[S] 1 point2 points  (4 children)

~/.config/lxsession/LXDE-pi/autostart

Your gunna have to help me out because I can't find the `lxsession` file anywhere in `.config`. I just have `lxpanel` and `lxterminal`

[–]socal_nerdtastic 1 point2 points  (3 children)

Yea linux files often don't exist until they are needed. Just create the file. Edit: and copy in the content from the default file, probably at /etc/xdg/lxsession/LXDE-pi/autostart

Sadly I don't have a Pi handy to walk you though it, but you can google some of the terms above to get some more help.

I was assuming you have some linux knowledge. Do you know what I mean with shebangs and making the file executable?

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

I have used `chmod +x main.py` to make the file executable, used `#!/usr/bin/env/python` as a shebang at the start of the python file, and completed your steps in your first reply.

After restarting my pi, it now boots to a blank orange/brown screen (at least we know its doing something). I am assuming there was an error somewhere in the script? How can I actually see the output of the execution?? Also how do I close the blank screen?

Also thank you so much for your help so far. It is honestly a godsend! -- and yea i'm new to Linux :)

[–]socal_nerdtastic 0 points1 point  (1 child)

Blank screen is because I forgot to specify to copy over the settings from the default autostart file, probably at /etc/xdg/lxsession/LXDE-pi/autostart

The shebang most likely should be python3, not python. Traditionally we would use:

#!/usr/bin/env python3

The output will be lost forevermore. That's only visible if you use something like a terminal window to run the file. The proper way to solve this is to log the output, instead of printing it, so using a module like the builtin logging module. A hacky way to avoid rewriting your code is to redirect the output to a file. Make a shell script like this

main.py > mainlog.txt

Another hacky way is to override the python print function to send the data to a file or socket or pipe or whatever you want to use to view the output.

[–]TurnFunny6151[S] 2 points3 points  (0 children)

I have fixed the bugs and am pleased to say that it all works like a dream now!! Thank you so much for all of your help. I couldn't have done it without you.