I have already installed pynotify, still getting e

2019-08-15 23:27发布

问题:

I have already installed pynotify using :

pip install py-notify

When I re-run this it shows :

Requirement already satisfied (use --upgrade to upgrade).

I also tried :

pip install --upgrade py-notify 

but it shows :

Requirement already up-to-date.

Below is my simple code to show desktop notification using pynotify.

import pynotify    
pynotify.init("Basic")

n = pynotify.Notification("Title", "Some sample content")
n.show()

What should I do now to run below code correctly?

回答1:

If you need to send GTK balloons - you've not installed correct library.

If you want to use "Observer programming pattern" (callback management) - you are using incorrect syntax.

There are two similar packages:

  • pynotify - wrapper for libnotify that shows desktop balloons to notify user about some events. Requires PyGTK (http://www.pygtk.org/) to work. Can't be installed from pip. Usually installed with some OS package (something like python-pynotify). Usage: import pygtk;pygtk.require('2.0');import pynotify.
  • notify2 (https://pypi.python.org/pypi/notify2) - alternative wrapper for libnotify. Can be installed from pip. Usage: import notify2

There are also two unrelated packages with similar names:

  • pyinotify (https://pypi.python.org/pypi/pyinotify) - wrapper for libinotify that allows to monitor filesystem changes. Usage: import pyinotify.
  • py-notify (https://pypi.python.org/pypi/py-notify) - python-only library that implements hooks (callback) storage, calling and filtering with no connections to outside world (third-party libraries or standards). Usage: import notify.


回答2:

faced same problem on Ubuntu 16.04

sudo apt-get install python-notify 

worked for me



回答3:

There's a names conflict with pynotify.

I had installed pynotify from PIP using:

sudo pip install pynotify

Since that was the wrong choice, I removed it with:


sudo pip uninstall pynotify

And then installed the expected pynotify using:

sudo apt install python-notify