当我尝试将 feedparser 库包含到交互式 Python 环境中时收到错误消息:
>>>> import feedparser
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named feedparser
BeautifulSoup 和 pydelicious 也会发生这种情况。为什么我会收到此错误?
使用 OS X 10.8.3,在 /usr/bin 目录中包含以下文件:
$ ll python*
-rwxr-xr-x 2 root wheel 58896 Mar 17 20:55 python
-rwxr-xr-x 6 root wheel 925 Nov 16 10:30 python-config
lrwxr-xr-x 1 root wheel 75 Nov 16 10:30 python2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
lrwxr-xr-x 1 root wheel 82 Nov 16 10:30 python2.5-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5-config
lrwxr-xr-x 1 root wheel 75 Nov 16 10:30 python2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
lrwxr-xr-x 1 root wheel 82 Nov 16 10:30 python2.6-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6-config
lrwxr-xr-x 1 root wheel 75 Nov 16 10:30 python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x 1 root wheel 82 Nov 16 10:30 python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
-rwxr-xr-x 2 root wheel 58896 Mar 17 20:55 pythonw
lrwxr-xr-x 1 root wheel 76 Nov 16 10:30 pythonw2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5
lrwxr-xr-x 1 root wheel 76 Nov 16 10:30 pythonw2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw2.6
lrwxr-xr-x 1 root wheel 76 Nov 16 10:30 pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
Python的位置:
$ which python
/usr/bin/python
Python的版本:
$ python -V
Python 2.7.2
这可能是不必要的,但我用 Homebrew 安装了 Python:
$ brew install python
其中安装了这些文件:
$ brew list python
/usr/local/Cellar/python/2.7.4/bin/smtpd2.py
/usr/local/Cellar/python/2.7.4/bin/smtpd2.7.py
/usr/local/Cellar/python/2.7.4/bin/smtpd.py
/usr/local/Cellar/python/2.7.4/bin/pythonw2.7
/usr/local/Cellar/python/2.7.4/bin/pythonw2
/usr/local/Cellar/python/2.7.4/bin/pythonw
/usr/local/Cellar/python/2.7.4/bin/python2.7-config
/usr/local/Cellar/python/2.7.4/bin/python2.7
/usr/local/Cellar/python/2.7.4/bin/python2-config
/usr/local/Cellar/python/2.7.4/bin/python2
/usr/local/Cellar/python/2.7.4/bin/python-config
/usr/local/Cellar/python/2.7.4/bin/python
/usr/local/Cellar/python/2.7.4/bin/pydoc2.7
/usr/local/Cellar/python/2.7.4/bin/pydoc2
/usr/local/Cellar/python/2.7.4/bin/pydoc
/usr/local/Cellar/python/2.7.4/bin/pip-2.7
/usr/local/Cellar/python/2.7.4/bin/pip
/usr/local/Cellar/python/2.7.4/bin/idle2.7
/usr/local/Cellar/python/2.7.4/bin/idle2
/usr/local/Cellar/python/2.7.4/bin/idle
/usr/local/Cellar/python/2.7.4/bin/easy_install-2.7
/usr/local/Cellar/python/2.7.4/bin/easy_install
/usr/local/Cellar/python/2.7.4/bin/2to3-2.7
/usr/local/Cellar/python/2.7.4/bin/2to3-2
/usr/local/Cellar/python/2.7.4/bin/2to3
/usr/local/Cellar/python/2.7.4/Build Applet.app/Contents/ (8 files)
/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/ (4858 files)
/usr/local/Cellar/python/2.7.4/IDLE.app/Contents/ (8 files)
/usr/local/Cellar/python/2.7.4/Python Launcher.app/Contents/ (17 files)
/usr/local/Cellar/python/2.7.4/share/man/ (3 files)
/usr/local/Cellar/python/2.7.4/share/python/ (317 files)
然后我安装了 feedparser:
$ pip install feedparser
这导致了这些文件:
$ ll /usr/local/lib/python2.7/site-packages/f*
-rw-r--r-- 1 foobar admin 166583 Apr 24 20:16 /usr/local/lib/python2.7/site-packages/feedparser.py
-rw-r--r-- 1 foobar admin 138040 Apr 24 20:16 /usr/local/lib/python2.7/site-packages/feedparser.pyc
我希望通过使用 Homebrew(它与其他库很好地配合)来避免这些问题。我错过了什么?