【问题标题】:python feedparser ImportError: No module named feedparserpython feedparser ImportError:没有名为feedparser的模块
【发布时间】:2013-04-23 20:36:15
【问题描述】:

当我尝试将 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(与其他库配合良好)来避免这些问题。我错过了什么?

【问题讨论】:

标签: python python-2.7 pip homebrew feedparser


【解决方案1】:

如果您的 Python 位于 /usr/bin/python,那么您使用的不是 Homebrew 构建的 Python,而是 OS X 默认的 Python。 (还要注意输出中的版本号差异。)因此,您使用 pip 安装的任何软件包都将安装到 Homebrew 空间中,但对于 OS X 提供的 Python 安装将不可见。 (OS X 不提供pip,所以这很像 Homebrew。)

您的修复很可能会更新您的路径以使 /usr/local/bin 出现在 /usr/bin 之前。

【讨论】:

    猜你喜欢
    • 2013-01-06
    • 2015-12-09
    • 2012-01-26
    • 2020-12-15
    • 2015-11-17
    • 2016-07-24
    • 2017-07-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多