我是Anaconda版Python新手,已经遇到了令人不快的问题。
我按照the instructions here安装了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]:
有趣的是,当我没有运行Anaconda的python包时,这些包可以很好地导入,删除后
# 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,以便它知道在哪里找到它们吗?
答案 0 :(得分:20)
在评论中,确定使用的pip
为/usr/bin/pip
;换句话说,系统pip
。系统pip
将安装到系统site-packages
中,而不是Anaconda的site-packages
。
解决方案是确保在安装与Anaconda一起使用的软件包时使用Anaconda的pip
。