title: python script won't run at startup ubuntu
body: <p>I try to run my python scrip at startup but it doesn't work.</p>
  
  <p>Here is my python script(doesn't work):</p>
  
  <pre><code>#!/usr/bin/env python
  
  import paho.mqtt.publish as publish
  from datetime import datetime
  
  t = str(datetime.now())
  print t
  with open("/home/james/mqtt/log.txt", "a+") as f:
      f.write("it works " + t + "\n")
  </code></pre>
  
  <p>Here is my python script(works):</p>
  
  <pre><code>#!/usr/bin/env python
  
  from datetime import datetime
  
  t = str(datetime.now())
  print t
  with open("/home/james/mqtt/log.txt", "a+") as f:
      f.write("it works " + t + "\n")
  </code></pre>
  
  <p>Here is my rc.local files(also try crontab and setting up service in /ect/init.d):</p>
  
  <pre><code>#!/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.
  
  # /bin/mqtt_test.py &amp;
  # mosquitto_sub -t "mqtt"
  
  /home/james/mqtt/script.sh
  # /etc/mqtt/mqtt_test.py
  
  exit 0
  </code></pre>
  
  <p>It look like by importing paho.mqtt.publish can make my script stop working, I am new to Linux, I have no idea why. Can someone help me out? Thanks for your help.</p>
  
  <p>Ubuntu 16.04</p>
  
  <p>Let me know if you need more info.</p>