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 name_of_script.py

You can check this worked by typing ./name_of_script.py 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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s