>>> import pynotify
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pynotify
>>>
我已经安装了 py-notify 模块。这是我导入它时遇到的错误,我一想到它就失去了理智。
我只是想知道是不是路径的问题。当我打印出 sys.path 时,我得到了这个输出。有什么建议吗?
>>> 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
>>>
最佳答案
通过阅读tutorial在py-notify
上,您将清楚地看到应该如何导入它。
你应该使用:
import notify
这是我在新的 python 2 virtualenv 中 pip 安装 py-notify 的完整示例,复制您的问题,然后按照教程所述正确导入:
▶ 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']
>>>
关于python - 尽管安装了模块,但导入错误 : No module named pynotify,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39307218/