2
>>> import pynotify
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pynotify
>>> 

I have installed py-notify module. This is the error I'm getting when I import it and I'm losing my mind thinking about it.

I just wonder if it's the problem with the path. When I print out sys.path, I get this output. Any suggestions?

>>> import sys
>>> for x in sys.path:
...     print x
... 

/usr/local/lib/python2.7/site-packages/distribute-0.6.14-py2.7.egg
/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/li b/python27.zip
/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/site-packages
/usr/local/lib/python2.7/site-packages/gtk-2.0
/usr/local/lib/python2.7/site-packages/gtk-2.0
>>> 
sagar_jeevan
  • 761
  • 5
  • 16
  • 34
  • Possible duplicate of [ImportError: No module named pynotify. While the module is installed](http://stackoverflow.com/questions/27096805/importerror-no-module-named-pynotify-while-the-module-is-installed) –  Sep 03 '16 at 13:04
  • Yeah but that didn't help me. – sagar_jeevan Sep 03 '16 at 13:04
  • 1
    What is the name of the script where you are importing pynotify? Do you have a script in your project called pynotify? – idjaw Sep 03 '16 at 13:05
  • see also [Problem with local modules shadowing global modules](http://stackoverflow.com/questions/491705/python-problem-with-local-modules-shadowing-global-modules) – Aprillion Sep 03 '16 at 13:06
  • @idjaw: I'm not importing it from the script..I'm running it through terminal. – sagar_jeevan Sep 03 '16 at 13:06
  • Do you know the directory where pynotify was installed? – John Gordon Sep 03 '16 at 13:08
  • did you restart python (or even command line if on windows) after the installation? are `python --version` and `pip --version` pointing to the same python? – Aprillion Sep 03 '16 at 13:09
  • @JohnGordon: Yes.. its installed in `py-notify in /usr/local/lib/python2.7/site-packages` – sagar_jeevan Sep 03 '16 at 13:10
  • @Aprillion : For python --version I get, `Python 2.7.12` and for pip --version, I get `pip 8.1.2 from /usr/local/lib/python2.7/site-packages (python 2.7)`. – sagar_jeevan Sep 03 '16 at 13:16

1 Answers1

1

By reading the tutorial on py-notify you will clearly see how you are supposed to import it.

You are supposed to use:

import notify

Here is a full example of me pip installing py-notify in a new python 2 virtualenv, replicating your problem, and then importing properly, per what the tutorial stated:

▶ pip install py-notify
Collecting py-notify
  Using cached py-notify-0.3.1.tar.gz
Building wheels for collected packages: py-notify
  Running setup.py bdist_wheel for py-notify ... done
  Stored in directory: /Users/####/Library/Caches/pip/wheels/50/af/6b/dd4386701fdb578f06c4c52e1dea195ae43b8bf9a7d0320e16
Successfully built py-notify
Installing collected packages: py-notify
Successfully installed py-notify-0.3.1
(venv2)
~/dev/rough
▶ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pynotify
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pynotify
>>> import notify
>>> dir(notify)
['__builtins__', '__doc__', '__docformat__', '__file__', '__name__', '__package__', '__path__', '__version__', 'version_tuple']
>>>
idjaw
  • 25,487
  • 7
  • 64
  • 83
  • I think I ended up looking for the wrong module. I was looking for module to create desktop notification, and I ended up here . He imports pynotify. – sagar_jeevan Sep 03 '16 at 13:28
  • I tried using it but it didn't seem to work..However, I found this helpful since I'm on OS X. – sagar_jeevan Sep 03 '16 at 16:42