23

我是 Python 的 Anaconda 版本的新手,我已经遇到了不愉快的问题。

我按照此处的说明安装了 Anaconda ,它的工作原理非常有魅力,所有包含的软件包都在需要时正确导入。然后我继续安装了一些 Anaconda 最初没有包含的额外软件包pip

$ sudo pip install BeautifulSoup mrjob pattern

安装似乎很完美,但是当我尝试在 ipython 中导入它们时,事情变得令人沮丧:

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]: 

有趣的是,当我不运行 Python 的 Anaconda 包时,这些包可以很好地导入,删除后

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

从我的.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]: 

在我运行的这些安装中,我有没有遗漏任何东西?我应该手动将这些包链接到 Anaconda 以便它知道在哪里可以找到它们吗?

4

1 回答 1

24

在评论中,确定pipin use 是/usr/bin/pip; 换句话说,系统pip。该系统pip将安装到系统中site-packages,而不是 Anaconda 的site-packages

解决方案是确保您pip在安装与 Anaconda 一起使用的软件包时使用的是 Anaconda。

于 2014-01-18T07:40:20.310 回答