2013-04-30 9 views
3

Je reçois une erreur lorsque je tente d'inclure la bibliothèque feedparser dans l'environnement Python interactif:python feedparser ImportError: Aucun module nommé feedparser

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

Cela se produit également avec BeautifulSoup et pydelicious. Pourquoi ai-je cette erreur?

En utilisant OS X 10.8.3, qui comprennent les fichiers suivants dans le répertoire/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 

emplacement de Python:

$ which python 
/usr/bin/python 

version de Python:

$ python -V 
Python 2.7.2 

C'était probablement inutile, mais j'ai installé Python avec Homebrew:

$ brew install python 

qui a installé ces fichiers:

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

Puis j'ai installé feedparser:

$ pip install feedparser 

Ce qui a donné lieu à ces fichiers:

$ 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 

J'espérais éviter ce genre des problèmes en utilisant Homebrew (qui a bien fonctionné avec d'autres libr bélier). Qu'est-ce que je rate?

+0

Les problèmes de configuration qui suivent inévitablement les installations manuelles de paquets (par opposition à un gestionnaire de paquets). – craig

+0

puis utilisez virtualenv – elssar

+0

duplication possible de [homebrew python par défaut] (http://stackoverflow.com/questions/5157678/python-homebrew-by-default) – craig

Répondre

2

Si votre Python est à /usr/bin/python, alors vous n'utilisez pas le Python construit par Homebrew, mais celui d'OS X par défaut. (Notez également les différences de numéro de version dans votre sortie.) Ainsi, tout package installé avec pip sera installé dans l'espace Homebrew, mais ne sera pas visible par l'installation de Python fournie par OS X. (OS X ne fournit pas pip, donc c'est tout à fait comme celui Homebrew.)

Le correctif pour vous est tout à fait susceptible de mettre à jour votre chemin pour avoir /usr/local/bin venir avant /usr/bin.

+0

Merci pour l'aide. – craig