title: Python 3 script using libnotify fails as cron job
body: <p>I've got a Python 3 script that gets some JSON from a URL, processes it, and notifies me if there's any significant changes to the data I get. I've tried using <a href="https://pypi.python.org/pypi/notify2" rel="nofollow">notify2</a> and <a href="https://live.gnome.org/PyGObject/" rel="nofollow">PyGObject</a>'s libnotify bindings (gi.repository.Notify) and get similar results with either method. This script works a-ok when I run it from a terminal, but chokes when cron tries to run it.</p>
  
  <pre><code>import notify2
  from gi.repository import Notify
  
  def notify_pygobject(new_stuff):
      Notify.init('My App')
      notify_str = '\n'.join(new_stuff)
      print(notify_str)
      popup = Notify.Notification.new('Hey! Listen!', notify_str,
                                      'dialog-information')
      popup.show()
  
  def notify_notify2(new_stuff):
      notify2.init('My App')
      notify_str = '\n'.join(new_stuff)
      print(notify_str)
      popup = notify2.Notification('Hey! Listen!', notify_str,
                                   'dialog-information')
      popup.show()
  </code></pre>
  
  <p>Now, if I create a script that calls <code>notify_pygobject</code> with a list of strings, cron throws this error back at me via the mail spool:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/p0lar_bear/Documents/devel/notify-test/test1.py", line 3, in &lt;module&gt;
      main()
    File "/home/p0lar_bear/Documents/devel/notify-test/test1.py", line 4, in main
      testlib.notify(notify_projects)
    File "/home/p0lar_bear/Documents/devel/notify-test/testlib.py", line 8, in notify
      popup.show()
    File "/usr/lib/python3/dist-packages/gi/types.py", line 113, in function
      return info.invoke(*args, **kwargs)
  gi._glib.GError: Error spawning command line `dbus-launch --autolaunch=776643a88e264621544719c3519b8310 --binary-syntax --close-stderr': Child process exited with code 1
  </code></pre>
  
  <p>...and if I change it to call <code>notify_notify2()</code> instead:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/p0lar_bear/Documents/devel/notify-test/test2.py", line 3, in &lt;module&gt;
      main()
    File "/home/p0lar_bear/Documents/devel/notify-test/test2.py", line 4, in main
      testlib.notify(notify_projects)
    File "/home/p0lar_bear/Documents/devel/notify-test/testlib.py", line 13, in notify
      notify2.init('My App')
    File "/usr/lib/python3/dist-packages/notify2.py", line 93, in init
      bus = dbus.SessionBus(mainloop=mainloop)
    File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 211, in __new__
      mainloop=mainloop)
    File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 100, in __new__
      bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
    File "/usr/lib/python3/dist-packages/dbus/bus.py", line 122, in __new__
      bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
  dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
  </code></pre>
  
  <p>I did some research and saw suggestions to put a <code>PATH=</code> into my crontab, or to export <code>$DISPLAY</code> (I did this within the script by calling <code>os.system('export DISPLAY=:0')</code>) but neither resulted in any change...</p>