我知道pip是python包的包管理器。但是,我在IPython的网站上看到了使用conda安装IPython的安装。
我可以用pip安装IPython吗?当我已经有pip时,为什么我要使用conda作为另一个python包管理器?
pip和conda的区别是什么?
我知道pip是python包的包管理器。但是,我在IPython的网站上看到了使用conda安装IPython的安装。
我可以用pip安装IPython吗?当我已经有pip时,为什么我要使用conda作为另一个python包管理器?
pip和conda的区别是什么?
引用Conda博客:
由于在python世界中工作了很长时间,我们都知道pip、easy_install和virtualenv,但是这些工具并不能满足我们所有的特定需求。主要的问题是它们关注Python,忽略了非Python库的依赖关系,如HDF5、MKL、LLVM等,这些库的源代码中没有setup.py,也没有将文件安装到Python的site-packages目录中。
因此,Conda是一个打包工具和安装程序,它的目标是比pip做的更多;处理Python包之外的库依赖项以及Python包本身。Conda还创建了一个虚拟环境,就像virtualenv一样。
因此,也许可以将Conda与Buildout进行比较,后者是另一个可以同时处理Python和非Python安装任务的工具。
因为Conda引入了一种新的打包格式,所以pip和Conda不能互换使用;pip无法安装Conda包格式。您可以同时使用这两个工具(通过使用conda install pip安装pip),但它们也不能互操作。
在写下这个答案后,Anaconda发表了一个关于理解Conda和Pip的新页面,这也与此相呼应:
这突出了conda和pip之间的一个关键区别。Pip安装Python包,而conda安装的包可能包含用任何语言编写的软件。例如,在使用pip之前,必须通过系统包管理器或下载并运行安装程序来安装Python解释器。另一方面,Conda可以直接安装Python包以及Python解释器。
再进一步
有时需要一个包,这个包不能作为conda包使用,但可以在PyPI上使用,并且可以用pip安装。在这些情况下,尝试同时使用conda和pip是有意义的。
免责声明:这个答案描述的是十年前的情况,当时pip还不支持二进制包。Conda是专门为更好地支持构建和分发二进制包而创建的,特别是带有C扩展的数据科学库。作为参考,pip只获得了带轮子的便携式二进制包的广泛支持(2013年的pip 1.4)和manylinux1规范(2016年3月的pip 8.1)。查看最近的答案了解更多历史。
以下是一个简短的概述:
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 build that builds packages from source, but conda install itself installs things from already built Conda packages. External. conda is an environment and package manager. It is included in the Anaconda Python distribution provided by Continuum Analytics (now called Anaconda, Inc.).
conda is an environment manager written in Python and is language-agnostic. conda environment management functions cover the functionality provided by venv, virtualenv, pipenv, pyenv, and other Python-specific package managers. You could use conda within an existing Python installation by pip installing it (though this is not recommended unless you have a good reason to use an existing installation). As of 2022, conda and pip are not fully aware of one another package management activities within a virtual environment, not are they interoperable for Python package management.
在这两种情况下:
用Python编写 开源(conda是BSD, pip是MIT) 警告:虽然conda本身是开源的,但包存储库由Anaconda Inc托管,并且在商业使用方面有限制。
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.
如果您对构建自己的包感兴趣,也有一些不同之处。例如,pip构建在setuptools之上,而conda使用自己的格式,这有一些优点(比如是静态的,并且与Python无关)。
其他答案对细节进行了合理的描述,但我想强调一些高级点。
PIP是一个包管理器,可以方便地安装、升级和卸载python包。它也适用于虚拟python环境。
Conda是任何软件(安装、升级和卸载)的包管理器。它还适用于虚拟系统环境。
conda设计的目标之一是方便用户所需的整个软件堆栈的包管理,其中一个或多个python版本可能只是一小部分。这包括低级库,如线性代数,编译器,如Windows上的mingw,编辑器,版本控制工具,如Hg和Git,或任何其他需要分发和管理的工具。
对于版本管理,pip允许您在多个python环境之间切换和管理。
Conda允许您在多个通用环境之间切换和管理,在这些环境中,许多其他东西的版本号可能不同,比如c库、编译器、测试套件或数据库引擎等等。
Conda不是以Windows为中心的,但在Windows上,当需要安装和管理需要编译的复杂科学包时,它是目前可用的最好的解决方案。
当我想到在Windows上通过pip编译许多这些包,或者在需要编译时调试失败的pip安装会话时,我浪费了多少时间,我想哭。
最后一点,Continuum Analytics还提供(免费的)binstar.org(现在叫anaconda.org),允许常规的软件包开发人员创建他们自己的自定义(构建的!)软件堆栈,他们的软件包用户可以从中安装conda。
为了不让你们更困惑, 但是你也可以在conda环境中使用PIP,它会验证上面的一般管理器注释和特定于python的管理器注释。
conda install -n testenv pip
source activate testenv
pip <pip command>
您还可以将PIP添加到任何环境的默认包中,以便每次都显示它,这样您就不必遵循上面的代码段。
WINDOWS用户
“标准”包装工具的情况最近有所改善:
截至2015年9月11日,pypi本身的车轮包装数量为48%(2015年5月为38%,2014年9月为24%), 最新的python 2.7.9版本现在支持开箱即用的wheel格式,
“标准”+“微调”包装工具的情况也在改善:
你可以在http://www.lfd.uci.edu/~gohlke/pythonlibs上找到几乎所有的科学软件包, mingwpy项目可能有一天会给Windows用户带来一个“编译”包,允许他们在需要的时候从源代码安装所有东西。
“Conda”包装对于它所服务的市场来说仍然更好,并强调了“标准”应该改进的地方。
(此外,在标准wheel系统和conda系统或buildout中的依赖规范multiple-effort不是很python化,如果所有这些打包“核心”技术可以通过某种PEP聚合在一起就好了)
引用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:
conda install pip
pip install gensim
引用Conda: Myths and misconcepts(一个全面的描述):
...
误解3:Conda和pip是直接竞争对手
事实:Conda和pip服务于不同的目的,并且只在一小部分任务上直接竞争:即在孤立的环境中安装Python包。
Pip是Pip安装包的缩写,是Python官方认可的包管理器,最常用于安装发布在Python包索引(PyPI)上的包。pip和PyPI都由Python打包管理局(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.
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.
Conda和pip不是竞争对手,而是专注于不同用户组和使用模式的工具。
我可以用pip安装iPython吗?
当然,两者都有(第一个方法)
pip install ipython
(第三种方法,第二种是conda)
您可以从GitHub或PyPI手动下载IPython。安装一个 对于这些版本,解压它并从顶层运行以下命令 源目录使用终端: PIP安装。
都是官方推荐的安装方式。
当我已经有pip时,为什么我要使用conda作为另一个python包管理器?
正如这里所说:
如果您需要一个特定的包(可能只用于一个项目),或者需要与其他人共享该项目,那么conda似乎更合适。
Conda在(YMMV)中超过pip
使用非python工具的项目 与同事分享 版本切换 在具有不同库版本的项目之间切换
pip和conda的区别是什么?
每个人都广泛地回答了这个问题。
pip仅用于Python
conda只适用于Anaconda +其他科学包,如R依赖等。并不是每个人都需要蟒蛇,因为它已经和Python一起出现了。Anaconda主要是为那些做机器学习/深度学习等的人准备的。普通的Python开发人员不会在他的笔记本电脑上运行Anaconda。
I may have found one further difference of a minor nature. I have my python environments under /usr rather than /home or whatever. In order to install to it, I would have to use sudo install pip. For me, the undesired side effect of sudo install pip was slightly different than what are widely reported elsewhere: after doing so, I had to run python with sudo in order to import any of the sudo-installed packages. I gave up on that and eventually found I could use sudo conda to install packages to an environment under /usr which then imported normally without needing sudo permission for python. I even used sudo conda to fix a broken pip rather than using sudo pip uninstall pip or sudo pip --upgrade install pip.
PIP是一个包管理器。
Conda既是包管理器,也是环境管理器。
细节:
依赖项检查
Pip and conda also differ in how dependency relationships within an environment are fulfilled. When installing packages, pip installs dependencies in a recursive, serial loop. No effort is made to ensure that the dependencies of all packages are fulfilled simultaneously. This can lead to environments that are broken in subtle ways, if packages installed earlier in the order have incompatible dependency versions relative to packages installed later in the order. In contrast, conda uses a satisfiability (SAT) solver to verify that all requirements of all packages installed in an environment are met. This check can take extra time but helps prevent the creation of broken environments. As long as package metadata about dependencies is correct, conda will predictably produce working environments.
参考文献
理解康达和皮普
要回答最初的问题, 对于安装包,PIP和Conda是完成相同任务的不同方式。两者都是安装包的标准应用程序。主要的区别是包文件的来源。
PIP/PyPI将有更多的“实验性”包,或者更新的、不太常见的包版本 Conda通常会有更完善的包或版本
一个重要的警告提示:如果使用两个源(pip和conda)在同一环境中安装包,以后可能会导致问题。
重建环境将更加困难 修复包不兼容性变得更加复杂
最佳实践是选择一个应用程序(PIP或Conda)来安装包,并使用该应用程序安装所需的任何包。 然而,仍然有许多例外或理由在conda环境中使用pip,反之亦然。 例如:
如果您需要的包只存在于一个包上,则 其他人没有。 您需要一个只在一个环境中可用的特定版本
(2021更新)
使用pip,它是Python 3以来的官方包管理器。
pip
basics pip is the default package manager for python pip is built-in as of Python 3.0 Usage: python3 -m venv myenv; source myenv/bin/activate; python3 -m pip install requests Packages are downloaded from pypi.org, the official public python repository It can install precompiled binaries (wheels) when available, or source (tar/zip archive). Compiled binaries are important because many packages are mixed Python/C/other with third-party dependencies and complex build chains. They MUST be distributed as binaries to be ready-to-use. advanced pip can actually install from any archive, wheel, or git/svn repo... ...that can be located on disk, or on a HTTP URL, or a personal pypi server. pip install git+https://github.com/psf/requests.git@v2.25.0 for example (it can be useful for testing patches on a branch). pip install https://download.pytorch.org/whl/cpu/torch-1.9.0%2Bcpu-cp39-cp39-linux_x86_64.whl (that wheel is Python 3.9 on Linux). when installing from source, pip will automatically build the package. (it's not always possible, try building TensorFlow without the google build system :D) binary wheels can be python-version specific and OS specific, see manylinux specification to maximize portability.
conda
You are NOT permitted to use Anaconda or packages from Anaconda repositories for commercial use, unless you acquire a license. Conda is a third party package manager from conda. It's popularized by anaconda, a Python distribution including most common data science libraries ready-to-use. You will use conda when you use anaconda. Packages are downloaded from the anaconda repo. It only installs precompiled packages. Conda has its own format of packages. It doesn't use wheels. conda install to install a package. conda build to build a package. conda can build the python interpreter (and other C packages it depends on). That's how an interpreter is built and bundled for anaconda. conda allows to install and upgrade the Python interpreter (pip does not). advanced Historically, the selling point of conda was to support building and installing binary packages, because pip did not support binary packages very well (until wheels and manylinux2010 spec). Emphasis on building packages. Conda has extensive build settings and it stores extensive metadata, to work with dependencies and build chains. Some projects use conda to initiate complex build systems and generate a wheel, that is published to pypi.org for pip.
easy_install/鸡蛋
For historical reference only. DO NOT USE egg is an abandoned format of package, it was used up to mid 2010s and completely replaced by wheels. an egg is a zip archive, it contains python source files and/or compiled libraries. eggs are used with easy_install and the first releases of pip. easy_install was yet another package manager, that preceded pip and conda. It was removed in setuptools v58.3 (year 2021). it too caused a lot of confusion, just like pip vs conda :D egg files are slow to load, poorly specified, and OS specific. Each egg was setup in a separate directory, an import mypackage would have to look for mypackage.py in potentially hundreds of directories (how many libraries were installed?). That was slow and not friendly to the filesystem cache.
从历史上看,上述三个工具都是开源的,并且是用Python编写的。 然而,conda背后的公司在2020年更新了他们的服务条款,禁止商业使用,小心!
有趣的事实:构建Python解释器唯一严格要求的依赖项是zlib(一个zip库),因为压缩是加载更多包所必需的。鸡蛋和轮子包是zip文件。
为什么有这么多选择?
问得好。
让我们深入研究Python和计算机的历史。= D
纯python包总是能很好地与这些打包器一起工作。问题不仅在于python包。
世界上大多数的代码都依赖于C,这对于Python解释器来说是如此,它是用C编写的。对于许多Python包来说也是如此,这些包是围绕C库的Python包装器或混合了Python /C/ c++代码的项目。
任何涉及SSL、压缩、GUI (X11和Windows子系统)、数学库、GPU、CUDA等的东西……通常与一些C代码相结合。
这给打包和分发Python库带来了麻烦,因为不仅仅是Python代码可以在任何地方运行。库必须编译,编译需要编译器、系统库和第三方库,然后一旦编译,生成的二进制代码只适用于特定的系统和python版本。
最初,python可以很好地分发纯python库,但是很少支持分发二进制库。在2010年前后,您尝试使用numpy或cassandra时会遇到很多错误。它下载了源代码,但是由于缺少依赖项而无法编译。或者它下载了一个预构建的包(当时可能是一个egg),在使用时崩溃并发生SEGFAULT,因为它是为另一个系统构建的。这简直是一场噩梦。
从2012年开始,pip和wheels解决了这个问题。然后等待许多年,让人们采用这些工具,并让这些工具传播到稳定的Linux发行版(许多开发人员依赖/usr/bin/python)。二进制包的问题一直延续到2010年代末。
作为参考,这就是为什么要运行的第一个命令是python3 -m venv myvenv && source myvenv/bin/activate && pip install -upgrade pip setuptools在旧系统上,因为操作系统自带的是5年前的旧python+pip,它有bug,不能识别当前的包格式。
Conda并行地研究他们自己的解决方案。Anaconda专门用于使数据科学库易于开箱即用(数据科学= C和c++无处不在),因此他们必须提出一个专门用于构建和分发二进制包的包管理器conda。
如果你现在安装任何带有pip install xxx的软件包,它都可以工作。这是推荐的安装包的方式,并且在当前版本的Python中是内置的。
这个答案来自于上面@user5994461的答案
您可以使用pip进行包管理。自Python 3以来,Pip是Python.org的官方内置包管理器。
PIP不是虚拟环境管理器。
pip
basics pip is the default package manager for python pip is built-in as of Python 3.0 Usage: python3 -m venv myenv; source myenv/bin/activate; python3 -m pip install requests Packages are downloaded from pypi.org, the official public python repository It can install precompiled binaries (wheels) when available, or source (tar/zip archive). Compiled binaries are important because many packages are mixed Python/C/other with third-party dependencies and complex build chains. They MUST be distributed as binaries to be ready-to-use. advanced pip can actually install from any archive, wheel, or git/svn repo... ...that can be located on disk, or on a HTTP URL, or a personal pypi server. pip install git+https://github.com/psf/requests.git@v2.25.0 for example (it can be useful for testing patches on a branch). pip install https://download.pytorch.org/whl/cpu/torch-1.9.0%2Bcpu-cp39-cp39-linux_x86_64.whl (that wheel is Python 3.9 on Linux). when installing from source, pip will automatically build the package. (it's not always possible, try building TensorFlow without the google build system :D) binary wheels can be python-version specific and OS specific, see manylinux specification to maximize portability.
conda
conda is an open source environment manager AND package manager maintained by the open source community. It is separate from Anaconda, Inc. and does not require a commercial license to use. conda is also bundled into Anaconda Navigator, a popular commercial Python distribution from Anaconda, Inc. Anaconda) that includes most common data science and Python developer libraries ready-to-use. You will use conda when you use Anaconda Navigator GUI. Packages may be downloaded from conda-forge, anaconda repo4, and other public and private conda package "channels" (aka repos). It only installs precompiled packages. conda has its own package format. It doesn't use wheels. conda install to install a package. conda build to build a package. conda can build the python interpreter (and other C packages it depends on). That's how an interpreter is built and bundled for Anaconda Navigator. conda allows to install and upgrade the Python interpreter (pip does not). advanced Historically, one selling point of conda was to support building and installing binary packages, because pip did not support binary packages very well (until wheels and manylinux2010 spec). Emphasis on building packages. conda has extensive build settings and it stores extensive metadata, to work with dependencies and build chains. Some projects use conda to initiate complex build systems and generate a wheel, that is published to pypi.org for pip. conda emphasizes building and managing virtual environments. conda is by design a programming language-agnostic virtual environment manager. conda can install and manage other package managers such as npm, pip, and other language package managers. Can I use Anaconda Navigator packages for commercial use? The new language states that use by individual hobbyists, students, universities, non-profit organizations, or businesses with less than 200 employees is allowed, and all other usage is considered commercial and thus requires a business relationship with Anaconda. (as of Oct 28, 2020) IF you are a large developer organization, i.e., greater than 200 employees, you are NOT permitted to use Anaconda or packages from Anaconda repository for commercial use, unless you acquire a license. Pulling and using (properly open-sourced) packages from conda-forge repository do not require commercial licenses from Anaconda, Inc. Developers are free to build their own conda packages using the packaging tools provided in the conda-forge infrastructure.
easy_install/鸡蛋
For historical reference only. DO NOT USE egg is an abandoned format of package, it was used up to mid 2010s and completely replaced by wheels. an egg is a zip archive, it contains python source files and/or compiled libraries. eggs are used with easy_install and the first releases of pip. easy_install was yet another package manager, that preceded pip and conda. It was removed in setuptools v58.3 (year 2021). it too caused a lot of confusion, just like pip vs conda :D egg files are slow to load, poorly specified, and OS specific. Each egg was setup in a separate directory, an import mypackage would have to look for mypackage.py in potentially hundreds of directories (how many libraries were installed?). That was slow and not friendly to the filesystem cache.
有趣的事实:构建Python解释器唯一严格要求的依赖项是zlib(一个zip库),因为压缩是加载更多包所必需的。鸡蛋和轮子包是zip文件。
为什么有这么多选择?
问得好。
让我们深入研究Python和计算机的历史。= D
纯python包总是能很好地与这些打包器一起工作。问题不仅在于python包。
世界上大多数的代码都依赖于C,这对于Python解释器来说是如此,它是用C编写的。对于许多Python包来说也是如此,这些包是围绕C库的Python包装器或混合了Python /C/ c++代码的项目。
任何涉及SSL、压缩、GUI (X11和Windows子系统)、数学库、GPU、CUDA等的东西……通常与一些C代码相结合。
这给打包和分发Python库带来了麻烦,因为不仅仅是Python代码可以在任何地方运行。库必须编译,编译需要编译器、系统库和第三方库,然后一旦编译,生成的二进制代码只适用于特定的系统和python版本。
最初,python可以很好地分发纯python库,但是很少支持分发二进制库。在2010年前后,您尝试使用numpy或cassandra时会遇到很多错误。它下载了源代码,但是由于缺少依赖项而无法编译。或者它下载了一个预构建的包(当时可能是一个egg),在使用时崩溃并发生SEGFAULT,因为它是为另一个系统构建的。这简直是一场噩梦。
从2012年开始,pip和wheels解决了这个问题。然后等待许多年,让人们采用这些工具,并让这些工具传播到稳定的Linux发行版(许多开发人员依赖/usr/bin/python)。二进制包的问题一直延续到2010年代末。
作为参考,这就是为什么要运行的第一个命令是python3 -m venv myvenv && source myvenv/bin/activate && pip install -upgrade pip setuptools在旧系统上,因为操作系统自带的是5年前的旧python+pip,它有bug,不能识别当前的包格式。
Continuum Analytics(后来更名为Anaconda, Inc.)并行开发他们自己的解决方案(发布为Anaconda Navigator)。Anaconda Navigator专门用于使数据科学库易于开箱即用(数据科学= C和c++无处不在),因此他们提出了一个专门用于构建和分发二进制包的包管理器,并将其构建到环境管理器conda中。
如果你现在安装任何带有pip install xxx的软件包,它通常都能正常工作。pip是安装内置到当前版本Python中的包的推荐方法。