سؤال

I receive an error when I attempt to include the feedparser library into the interactive Python environment:

>>>> import feedparser
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named feedparser

This also happens with BeautifulSoup and pydelicious. Why am I getting this error?

Using OS X 10.8.3, which include the following files in the /usr/bin directory:

$ 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's location:

$ which python
/usr/bin/python

Python's version:

$ python -V
Python 2.7.2

It was probably unnecessary, but I installed Python with Homebrew:

$ brew install python

Which installed these files:

$ 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)

Then I installed feedparser:

$ pip install feedparser

Which resulted in these files:

$ 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

I was hoping to avoid these sorts of problems by using Homebrew (which has worked well with other libraries). What am I missing?

هل كانت مفيدة؟

المحلول

If your Python is at /usr/bin/python, then you are not using the Homebrew-built Python, but the OS X default one. (Also note the version number discrepancies in your output.) So any package that you install with pip will be installed into the Homebrew space, but will not be visible to the OS X-supplied Python installation. (OS X does not supply pip, so that's quite like the Homebrew one.)

The fix for you is quite likely to update your path to have /usr/local/bin come before /usr/bin.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top