Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

python - Anaconda not finding my packages installed with `pip`

I'm new to Anaconda version of Python, and already I'm running into unpleasant problems.

I installed Anaconda per the instructions here, and it worked like charm, with all the included packages imported properly when demanded. Then I went on to install some extra packages which Anaconda did not included in the first place with pip:

$ sudo pip install BeautifulSoup mrjob pattern

The installations seems to be perfect, but when I try to import them in ipython, things get frustrating:

Python 2.7.6 |Anaconda 1.8.0 (64-bit)| (default, Nov 11 2013, 10:47:18) 
Type "copyright", "credits" or "license" for more information.

IPython 1.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import BeautifulSoup
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-aa1e12a76f5e> in <module>()
----> 1 import BeautifulSoup

ImportError: No module named BeautifulSoup

In [2]: import mrjob
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-6ea1b9bda48b> in <module>()
----> 1 import mrjob

ImportError: No module named mrjob

In [3]: import pattern
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-4b662941bac1> in <module>()
----> 1 import pattern

ImportError: No module named pattern

In [4]: 

Funny thing is, these packages can be very well imported when I'm not running the Anaconda bundle of python, after removing

# added by Anaconda 1.8.0 installer
export PATH="/home/username/anaconda/bin:$PATH"

from my .bashrc:

Python 2.7.5+ (default, Sep 19 2013, 13:48:49) 
Type "copyright", "credits" or "license" for more information.

IPython 0.13.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import BeautifulSoup

In [2]: import mrjob

In [3]: import pattern

In [4]: 

Did I miss anything during any of these installations that I ran? Should I manually link these packages to Anaconda so that it knows where to find them?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In the comments, it was determined that the pip in use was /usr/bin/pip; in other words, the system pip. The system pip will install into the system site-packages, not Anaconda's site-packages.

The solution is to make sure you're using Anaconda's pip when installing packages for use with Anaconda.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...