当我尝试将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.7Python的位置:
$ which python
/usr/bin/pythonPython的版本:
$ 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来避免这类问题(Homebrew与其他库配合得很好)。我遗漏了什么?
发布于 2013-05-03 20:27:55
如果您的Python是在/usr/bin/python上,那么您使用的不是自制的Python,而是OS默认的Python。(还要注意输出中的版本号差异。)因此,您使用pip安装的任何包都将安装到Homebrew空间,但对于OS提供的Python安装是不可见的。(OS不提供pip,所以它和自制的很像。)
你的修复很可能会更新你的path,让/usr/local/bin在/usr/bin之前出现。
https://stackoverflow.com/questions/16291170
复制相似问题