Python pip 和 conda 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20994716/
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 21:44:40  来源:igfitidea点击:

What is the difference between pip and conda?

pythonpipipythonpackage-managersconda

提问by lazywei

I know pipis a package manager for python packages. However, I saw the installation on IPython's website use condato install IPython.

我知道pip是 python 包的包管理器。但是,我看到 IPython 网站conda上的安装用于安装 IPython。

Can I use pipto install IPython? Why should I use condaas another python package manager when I already have pip?

我可以pip用来安装 IPython 吗?conda当我已经有了时,为什么要用作另一个 python 包管理器pip

What is the difference between pipand conda?

pip和 和有conda什么区别?

采纳答案by Martijn Pieters

Quoting from the Conda blog:

引自Conda 博客

Having been involved in the python world for so long, we are all aware of pip, easy_install, and virtualenv, but these tools did not meet all of our specific requirements. The main problem is that they are focused around Python, neglecting non-Python library dependencies, such as HDF5, MKL, LLVM, etc., which do not have a setup.py in their source code and also do not install files into Python's site-packages directory.

涉足python世界这么久,我们都知道pip、easy_install和virtualenv,但这些工具并不能满足我们所有的具体要求。主要问题是他们专注于 Python,忽略了非 Python 库依赖项,例如 HDF5、MKL、LLVM 等,它们的源代码中没有 setup.py,也不会将文件安装到 Python 的站点中-packages 目录。

So Conda is a packaging tool and installer that aims to do more than what pipdoes; handle library dependencies outsideof the Python packages as well as the Python packages themselves. Conda also creates a virtual environment, like virtualenvdoes.

因此,Conda 是一个打包工具和安装程序,其目的不仅仅是做什么pip;处理Python 包之外的库依赖项以及 Python 包本身。Conda 也像virtualenv这样创建了一个虚拟环境。

As such, Conda should be compared to Buildoutperhaps, another tool that lets you handle both Python and non-Python installation tasks.

因此,应该将 Conda 与Buildout进行比较,后者是另一种可让您同时处理 Python 和非 Python 安装任务的工具。

Because Conda introduces a new packaging format, you cannot use pipand Conda interchangeably; pipcannot install the Conda package format. You can use the two tools side by side (by installing pipwith conda install pip) but they do not interoperate either.

因为 Conda 引入了一种新的包装格式,所以不能pip和 Conda 互换使用; pip无法安装 Conda 包格式。您可以使用并排的两个工具侧(通过安装pipconda install pip),但他们不具备互操作性无论是。

Since writing this answer, Anaconda has published a new page on Understanding Conda and Pip, which echoes this as well:

自从写下这个答案后,Anaconda 发布了一个关于理解 Conda 和 Pip新页面,这也呼应了这一点:

This highlights a key difference between conda and pip. Pip installs Python packages whereas conda installs packages which may contain software written in any language. For example, before using pip, a Python interpreter must be installed via a system package manager or by downloading and running an installer. Conda on the other hand can install Python packages as well as the Python interpreter directly.

这突出了 conda 和 pip 之间的主要区别。Pip 安装 Python 包,而 conda 安装可能包含用任何语言编写的软件的包。例如,在使用 pip 之前,必须通过系统包管理器或通过下载并运行安装程序来安装 Python 解释器。另一方面,Conda 可以直接安装 Python 包以及 Python 解释器。

and further on

并进一步

Occasionally a package is needed which is not available as a conda package but is available on PyPI and can be installed with pip. In these cases, it makes sense to try to use both conda and pip.

有时需要一个包,它不能作为 conda 包提供,但在 PyPI 上可用并且可以使用 pip 安装。在这些情况下,尝试同时使用 conda 和 pip 是有意义的。

回答by asmeurer

Here is a short rundown:

这是一个简短的概述:

pip

点子

  • Python packages only.
  • Compiles everything from source. EDIT: pip now installs binary wheels, if they are available.
  • Blessed by the core Python community (i.e., Python 3.4+ includes code that automatically bootstraps pip).
  • 仅限 Python 包。
  • 从源代码编译所有内容。编辑:pip 现在安装二进制轮子(如果可用)。
  • 受到核心 Python 社区的祝福(即,Python 3.4+ 包含自动引导 pip 的代码)。

conda

康达

  • Python agnostic. The main focus of existing packages are for Python, and indeed Conda itself is written in Python, but you can also have Conda packages for C libraries, or R packages, or really anything.
  • Installs binaries. There is a tool called conda buildthat builds packages from source, but conda installitself installs things from already built Conda packages.
  • External. Conda is the package manager of Anaconda, the Python distribution provided by Continuum Analytics, but it can be used outside of Anaconda too. You can use it with an existing Python installation by pip installing it (though this is not recommended unless you have a good reason to use an existing installation).
  • Python 不可知论者。现有包的主要焦点是用于 Python,实际上 Conda 本身是用 Python 编写的,但您也可以拥有用于 C 库、R 包或其他任何东西的 Conda 包。
  • 安装二进制文件。有一个叫做conda build从源代码构建包的工具,但conda install它本身从已经构建的 Conda 包中安装东西。
  • 外部的。Conda 是 Anaconda 的包管理器,Anaconda 是 Continuum Analytics 提供的 Python 发行版,但它也可以在 Anaconda 之外使用。您可以通过 pip 安装将它与现有的 Python 安装一起使用(尽管不建议这样做,除非您有充分的理由使用现有安装)。

In both cases:

在这两种情况下:

  • Written in Python
  • Open source (Conda is BSD and pip is MIT)
  • 用 Python 编写
  • 开源(Conda 是 BSD,pip 是 MIT)

The first two bullet points of Conda are really what make it advantageous over pip for many packages. Since pip installs from source, it can be painful to install things with it if you are unable to compile the source code (this is especially true on Windows, but it can even be true on Linux if the packages have some difficult C or FORTRAN library dependencies). Conda installs from binary, meaning that someone (e.g., Continuum) has already done the hard work of compiling the package, and so the installation is easy.

Conda 的前两个要点确实使它在许多软件包中优于 pip。由于 pip 从源代码安装,如果您无法编译源代码,用它安装东西可能会很痛苦(这在 Windows 上尤其如此,但如果包有一些困难的 C 或 FORTRAN 库,它甚至可以在 Linux 上如此依赖)。Conda 从二进制安装,这意味着有人(例如,Continuum)已经完成了编译包的繁重工作,因此安装很容易。

There are also some differences if you are interested in building your own packages. For instance, pip is built on top of setuptools, whereas Conda uses its own format, which has some advantages (like being static, and again, Python agnostic).

如果您有兴趣构建自己的包,也有一些差异。例如,pip 建立在 setuptools 之上,而 Conda 使用自己的格式,它具有一些优点(例如是静态的,同样,与 Python 无关)。

回答by Caleb Hattingh

The other answers give a fair description of the details, but I want to highlight some high-level points.

其他答案对细节进行了公正的描述,但我想强调一些高层次的观点。

pip is a package manager that facilitates installation, upgrade, and uninstallation of python packages. It also works with virtual pythonenvironments.

pip 是一个包管理器,方便安装、升级和卸载python 包。它也适用于虚拟python环境。

conda is a package manager for any software(installation, upgrade and uninstallation). It also works with virtual systemenvironments.

conda 是任何软件(安装、升级和卸载)的包管理器。它还适用于虚拟系统环境。

One of the goals with the design of conda is to facilitate package management for the entire software stack required by users, of which one or more python versions may only be a small part. This includes low-level libraries, such as linear algebra, compilers, such as mingw on Windows, editors, version control tools like Hg and Git, or whatever else requires distribution and management.

conda 的设计目标之一是方便用户所需的整个软件堆栈的包管理,其中一个或多个 python 版本可能只是一小部分。这包括低级库,例如线性代数、编译器(例如 Windows 上的 mingw)、编辑器、版本控制工具(例如 Hg 和 Git),或任何其他需要分发和管理的东西

For version management, pip allows you to switch between and manage multiple pythonenvironments.

对于版本管理,pip 允许您在多个python环境之间切换和管理。

Conda allows you to switch between and manage multiple general purpose environmentsacross which multiple other things can vary in version number, like C-libraries, or compilers, or test-suites, or database engines and so on.

Conda 允许您在多个通用环境之间切换和管理,在这些环境中,多个其他东西的版本号可能会有所不同,例如 C 库、编译器、测试套​​件或数据库引擎等。

Conda is not Windows-centric, but on Windows it is by far the superior solution currently available when complex scientific packages requiring compilation are required to be installed and managed.

Conda 不是以 Windows 为中心的,但在 Windows 上,当需要安装和管理需要编译的复杂科学包时,它是目前可用的卓越解决方案。

I want to weep when I think of how much time I have lost trying to compile many of these packages via pip on Windows, or debug failed pip installsessions when compilation was required.

当我想到在 Windows 上尝试通过 pip 编译许多这些包或pip install在需要编译时调试失败的会话时已经浪费了多少时间,我想哭。

As a final point, Continuum Analytics also hosts (free) binstar.org(now called anaconda.org) to allow regular package developers to create their own custom (built!) software stacks that their package-users will be able to conda installfrom.

最后一点,Continuum Analytics 还托管(免费)binstar.org(现在称为anaconda.org),以允许常规软件包开发人员创建他们自己的定制(构建!)软件堆栈,他们的软件包用户将能够使用这些软件堆栈conda install

回答by vijay venkatesh

Not to confuse you further, but you can also use pip within your conda environment, which validates the general vs. python specific managers comments above.

不要进一步混淆你,但你也可以在你的 conda 环境中使用 pip,它验证上面的一般与 python 特定管理器的评论。

conda install -n testenv pip
source activate testenv
pip <pip command>

you can also add pip to default packages of any environment so it is present each time so you don't have to follow the above snippet.

您还可以将 pip 添加到任何环境的默认包中,以便每次都存在它,因此您不必遵循上述代码段。

回答by stonebig

For WINDOWS users

对于 WINDOWS 用户

"standard" packaging tools situation is improving recently:

“标准”打包工具的情况最近有所好转:

  • on pypi itself, there are now 48% of wheel packages as of sept. 11th 2015 (up from 38% in may 2015 , 24% in sept. 2014),

  • the wheel format is now supported out-of-the-box per latest python 2.7.9,

  • 在 pypi 本身上,截至 9 月,现在有 48% 的车轮包。2015 年 11 日(从 2015 年 5 月的 38% 和 2014 年 9 月的 24% 上升),

  • 现在,每个最新的python 2.7.9 都支持开箱即用的wheel 格式,

"standard"+"tweaks" packaging tools situation is improving also:

“标准”+“调整”打包工具的情况也在改善:

  • you can find nearly all scientific packages on wheel format at http://www.lfd.uci.edu/~gohlke/pythonlibs,

  • the mingwpy project may bring one day a 'compilation' package to windows users, allowing to install everything from source when needed.

  • 你可以在http://www.lfd.uci.edu/~gohlke/pythonlibs找到几乎所有关于轮格式的科学包,

  • mingwpy 项目可能有一天会为 Windows 用户带来一个“编译”包,允许在需要时从源代码安装所有内容。

"Conda" packaging remains better for the market it serves, and highlights areas where the "standard" shouldimprove.

“Conda”包装对于它所服务的市场来说仍然更好,并突出了“标准”应该改进的领域。

(also, the dependency specification multiple-effort, in standard wheel system and in conda system, or buildout, is not very pythonic, it would be nice if all these packaging 'core' techniques could converge, via a sort of PEP)

(此外,在标准轮系统和 conda 系统或构建中,依赖规范的多重努力并不是非常 Pythonic,如果所有这些打包“核心”技术能够通过某种 PEP 融合,那就太好了)

回答by CheTesta

Quote from Conda for Data Sciencearticle onto Continuum's website:

Conda for Data Science文章引用到 Continuum 的网站:

Conda vs pip

Python programmers are probably familiar with pip to download packages from PyPI and manage their requirements. Although, both conda and pip are package managers, they are very different:

  • Pip is specific for Python packages and conda is language-agnostic, which means we can use conda to manage packages from any language Pip compiles from source and conda installs binaries, removing the burden of compilation
  • Conda creates language-agnostic environments natively whereas pip relies on virtualenv to manage only Python environments Though it is recommended to always use conda packages, conda also includes pip, so you don't have to choose between the two. For example, to install a python package that does not have a conda package, but is available through pip, just run, for example:

康达 vs pip

Python 程序员可能熟悉 pip 从 PyPI 下载包并管理他们的需求。虽然 conda 和 pip 都是包管理器,但它们非常不同:

  • Pip 专用于 Python 包,而 conda 与语言无关,这意味着我们可以使用 conda 来管理来自任何语言的包 Pip 从源代码编译,conda 安装二进制文件,消除编译负担
  • Conda 在本机创建与语言无关的环境,而 pip 依赖 virtualenv 仅管理 Python 环境虽然建议始终使用 conda 包,但 conda 也包含 pip,因此您不必在两者之间进行选择。例如,要安装一个没有 conda 包但可以通过 pip 获得的 python 包,只需运行,例如:
conda install pip
pip install gensim

回答by sancho.s ReinstateMonicaCellio

Quoting from Conda: Myths and Misconceptions(a comprehensive description):

引用Conda:神话和误解(综合描述):

...

...

Myth #3: Conda and pip are direct competitors

误区三:Conda 和 pip 是直接竞争对手

Reality: Conda and pip serve different purposes, and only directly compete in a small subset of tasks: namely installing Python packages in isolated environments.

现实:Conda 和 pip 服务于不同的目的,并且只在一小部分任务中直接竞争:即在隔离环境中安装 Python 包。

Pip, which stands for Pip Installs Packages, is Python's officially-sanctioned package manager, and is most commonly used to install packages published on the Python Package Index (PyPI). Both pip and PyPI are governed and supported by the Python Packaging Authority (PyPA).

皮普,代表PIPnstalls Packages,是Python的官方认可的包管理器,并且是最常用的在其上安装Python包索引(PyPI中)发布的数据包。pip 和 PyPI 均由 Python Packaging Authority (PyPA) 管理和支持。

In short, pip is a general-purpose manager for Python packages; conda is a language-agnostic cross-platform environment manager. For the user, the most salient distinction is probably this: pip installs python packages within any environment; conda installs any package within conda environments. If all you are doing is installing Python packages within an isolated environment, conda and pip+virtualenv are mostly interchangeable, modulo some difference in dependency handling and package availability. By isolated environment I mean a conda-env or virtualenv, in which you can install packages without modifying your system Python installation.

简而言之,pip 是一个通用的 Python 包管理器;conda 是一个与语言无关的跨平台环境管理器。对于用户来说,最显着的区别大概就是这个:pip在任何环境下都安装python包;conda 在 conda 环境中安装任何包。如果您所做的只是在隔离的环境中安装 Python 包,则 conda 和 pip+virtualenv 大多可以互换,以依赖处理和包可用性为模的一些差异。我所说的隔离环境是指 conda-env 或 virtualenv,您可以在其中安装软件包而无需修改系统 Python 安装。

Even setting aside Myth #2, if we focus on just installation of Python packages, conda and pip serve different audiences and different purposes. If you want to, say, manage Python packages within an existing system Python installation, conda can't help you: by design, it can only install packages within conda environments. If you want to, say, work with the many Python packages which rely on external dependencies (NumPy, SciPy, and Matplotlib are common examples), while tracking those dependencies in a meaningful way, pip can't help you: by design, it manages Python packages and only Python packages.

即使撇开神话#2,如果我们只关注 Python 包的安装,conda 和 pip 服务于不同的受众和不同的目的。如果您想在现有系统 Python 安装中管理 Python 包,conda 帮不了你:按照设计,它只能在 conda 环境中安装包。如果你想使用许多依赖外部依赖的 Python 包(NumPy、SciPy 和 Matplotlib 是常见的例子),同时以一种有意义的方式跟踪这些依赖,pip 不能帮助你:按照设计,它管理 Python 包并且仅管理 Python 包。

Conda and pip are not competitors, but rather tools focused on different groups of users and patterns of use.

Conda 和 pip 不是竞争对手,而是专注于不同用户群体和使用模式的工具。

回答by serv-inc

Can I use pip to install iPython?

我可以使用 pip 安装 iPython 吗?

Sure, both (first approach on page)

当然,两者(页面上的第一种方法)

pip install ipython

and (third approach, second is conda)

和(第三种方法,第二种方法是conda

You can manually download IPython from GitHub or PyPI. To install one of these versions, unpack it and run the following from the top-level source directory using the Terminal:

pip install .

您可以从 GitHub 或 PyPI 手动下载 IPython。要安装这些版本之一,请解压缩它并使用终端从顶级源目录运行以下命令:

pip install .

are officially recommended ways to install.

官方推荐的安装方式

Why should I use conda as another python package manager when I already have pip?

当我已经有了 pip 时,为什么要使用 conda 作为另一个 python 包管理器?

As said here:

正如这里所说:

If you need a specific package, maybe only for one project, or if you need to share the project with someone else, conda seems more appropriate.

如果您需要一个特定的包,可能只用于一个项目,或者您需要与其他人共享该项目,则 conda 似乎更合适。

Conda surpasses pip in (YMMV)

Conda 超过 pip ( YMMV)

  • projects that use non-python tools
  • sharing with colleagues
  • switching between versions
  • switching between projects with different library versions
  • 使用非 Python 工具的项目
  • 与同事分享
  • 版本间切换
  • 在具有不同库版本的项目之间切换

What is the difference between pip and conda?

pip 和 conda 有什么区别?

That is extensively answered by everyone else.

这是其他人广泛回答的。

回答by Galapagos

pipis for Python only

pip仅适用于 Python

condais only for Anaconda + other scientific packages like R dependencies etc. NOT everyone needs Anaconda that already comes with Python. Anaconda is mostly for those who do Machine learning/deep learning etc. Casual Python dev won't run Anaconda on his laptop.

conda仅适用于 Anaconda + 其他科学软件包,如 R 依赖项等。不是每个人都需要 Python 自带的 Anaconda。Anaconda 主要适用于那些从事机器学习/深度学习等工作的人。休闲 Python 开发人员不会在他的笔记本电脑上运行 Anaconda。

回答by J B

I may have found one further difference of a minor nature. I have my python environments under /usrrather than /homeor whatever. In order to install to it, I would have to use sudo install pip. For me, the undesired side effect of sudo install pipwas slightly different than what are widely reported elsewhere: after doing so, I had to run pythonwith sudoin order to import any of the sudo-installed packages. I gave up on that and eventually found I could use sudo condato install packages to an environment under /usrwhich then imported normally without needing sudopermission for python. I even used sudo condato fix a broken piprather than using sudo pip uninstall pipor sudo pip --upgrade install pip.

我可能已经发现了另一个性质较小的差异。我有我的 python 环境/usr而不是/home或其他。为了安装到它,我必须使用sudo install pip. 对我来说,不想要的副作用sudo install pip是比被广泛报道的其他地方略有不同:这样做之后,我还得跑pythonsudo以进口任何的sudo-installed包。我放弃了对,最终发现我可以用sudo conda将包安装到下一个环境/usr,然后正常进口,而无需sudo许可python。我什sudo conda至曾经修复损坏的pip而不是使用sudo pip uninstall pipor sudo pip --upgrade install pip