Python Anaconda 找不到我用`pip` 安装的软件包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21201003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 22:17:30  来源:igfitidea点击:

Anaconda not finding my packages installed with `pip`

pythonpipanaconda

提问by alxyzc

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

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

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:

按照此处的说明安装了 Anaconda ,它的工作非常出色,所有包含的包都在需要时正确导入。然后我继续安装一些额外的软件包,Anaconda 首先没有包含这些软件包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:

安装似乎很完美,但是当我尝试在 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]: 

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

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

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

from my .bashrc:

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

在我运行的任何这些安装过程中,我是否遗漏了什么?我应该手动将这些包链接到 Anaconda 以便它知道在哪里可以找到它们吗?

采纳答案by icktoofay

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

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

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

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