I am (trying) to write a simple python script for ubuntu based OS. As part of script, a notification is also shown. Now, I have gone through a number of posts over here but with each one I have an accompanying question (and some problem). Following are different ways, I have already tried (and associated issue),

Using notify2

This has largely worked well. However, with following issue,

a. For some reason, icon isn't being shown in notification bubble and there is no error. A simple print statement,print(os.path.abspath('icon.svg'), returning path, yields correct path but still no image.

Here's the exact code I am using,

def show_notification(title, content):
    n = notify2.Notification(title, content, os.path.abspath('icon.svg'))

Using from gi.repository import Notify

Following the hello-unity file here. I tried to use Notify. I have not been able to get this running at all! The last time I tried, I got an error ImportError: cannot import name Notify by running the script like python test.py.

Running the same using python3 as in python3 test.py results in a different error ImportError: cannot import name Notify, introspection typelib not found.

To overcome this, I did try to install python-gobject and libnotify-bin but these are already installed on my system (Elementary OS Loki). The errors still persists.

Using subprocess

This has worked without any problem but I am not sure if this is the best way to show notification since I intend to show regular notifications. This is the code I used,

import subprocess as s

Core question

Since this is the first time I am trying to develop for linux community (or rather Ubuntu), I am fairly new to linux development. Trying to search for a simple (and correct) implementation such as that of notification has been rather time consuming and confusing. Apart from suggesting the right way of implementing notifications, I will appreciate if someone could point me in the right direction, something like android developer guide which shows or has api references.

And before anyone asks about my development preferences, I am more comfortable with python. Regarding GUI, again I am not sure which path to take although GTK seems to be more popular.

1 Answer 1


Calling notifications from applications on Ubuntu

Definitely the third one, using either subprocess.call() or subprocess.Popen(). Noting to import but subprocess. Nothing new to install. Simple and easy, always works perfectly.

A few examples:

  1. Simply a text notification:

    subprocess.Popen(["notify-send", "some text"])

    enter image description here

  2. A title and some text:

    subprocess.Popen(["notify-send", "Title", "some text"])

    enter image description here

  3. An icon, a title and some text:

    img = "/path/to/icon.png"
    subprocess.Popen(["notify-send", "-i", img, "Title", "some text"])

    enter image description here

  • Apart from the advantage of not relying on any library, what other advantages does it carry? And why are there alternatives like that of Notify2, etc.? Secondly, Ubuntu is showing notification correctly, however Elementary OS (ubuntu based) is missing icon (with no warning/error).
    – Paritosh
    Nov 4, 2016 at 22:28
  • @Paritosh if your question is on elementary, it is unfortunately off topic here. Nov 4, 2016 at 22:29
  • I understand that but isn't using a core system functionality supposed to behave in a similar fashion across all ubuntu based distributions?
    – Paritosh
    Nov 4, 2016 at 22:31
  • 2
    @Paritosh not necessarily, other distros may make alterations where they like. Ubuntu developers have no control over that. Your comment proves functionality is not always the same. Nov 4, 2016 at 22:34
  • Aha. Thanks for clarification. Now if only there was a goto source for some guidelines to bring a level of sanity while developing for Ubuntu!
    – Paritosh
    Nov 4, 2016 at 22:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .