Run Python Script on OS boot

Place the script into /etc/rc.local . Scripts there run as root when the system starts. It is also suitable for Raspberry Pi, as you specified in the comments.

In your case you want to run it as python /path/to/script.py &

Here's my sample rc.local file, I use the same approach to run battery and temperature monitoring scripts

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/home/xieerqi/bin/batmon.sh &
/home/xieerqi/bin/preventShutdown.sh &
/home/xieerqi/bin/sh/temperature.sh  &

Additional info on /etc/rc.local


You can also do this with cron by adding the following to your crontab:

@reboot username python /python/to/file.py

You may or may not need the username in there.


[EDIT]

There are two caveats to this approach:

  1. the cron daemon must be running (which is the case under normal circumstances);
  2. the script or the crontab file must include the environment variables (if any) that will be needed.