当我尝试将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避免这些问题(Homebrew与其他库一起运行良好)。我错过了什么?
答案 0 :(得分:3)
如果您的Python位于/usr/bin/python
,那么您不使用Homebrew构建的Python,而是使用OS X默认的Python。 (另请注意输出中的版本号差异。)因此,使用pip
安装的任何软件包都将安装到Homebrew空间中,但OS X提供的Python安装不会显示。 (OS X不提供pip
,因此它与Homebrew非常相似。)
针对您的修复很可能会更新/usr/local/bin
/usr/bin
之前的路径。