How to Auto-run a Python Script in the Terminal of a Raspberry Pi When it Boots

1. Add this shebang in the first line of your script:

#!/usr/bin/env python

2. Make it executable by changing directory to where the script is and running this in your terminal:

chmod +x

You can check this worked by typing ./ in the directory and seeing if it runs.

3. edit (using nano) ~/.config/lxsession/LXDE-pi/autostart to include the line:

@lxterminal --command='path_to_your_now_executable_python_script'

Now type, in your terminal, “reboot” to test.

Good luck!