Python pyenv、virtualenv、anaconda 有什么区别?

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

What is the difference between pyenv, virtualenv, anaconda?

pythonpipanacondavirtualenvpyenv

提问by channa ly

I am a ruby programmer trying to learn python. I am pretty family with pyenv since it is like a copy and paste from rbenv. Pyenv helps allow to have more than one version of python in a system and also to isolate the python without touching sensitive part of system.

我是一个试图学习 python 的 ruby​​ 程序员。我是 pyenv 的家人,因为它就像是 rbenv 的复制和粘贴。Pyenv 有助于允许在一个系统中拥有多个版本的 python,并且还可以在不接触系统敏感部分的情况下隔离 python。

I suppose every python installation come with pip package. What I still don't understand is, there are many good python libs out there that suggest to use this virtualenv and anaconda. I can even find virtualenv plugin for pyenv.

我想每个 python 安装都带有 pip 包。我仍然不明白的是,有很多好的 python 库建议使用这个 virtualenv 和 anaconda。我什至可以找到 pyenv 的 virtualenv 插件。

Now I am getting confused with the purpose of these two pyenv and virtualenv. worse inside pyenv there is a virtualenv plugin.

现在我对这两个 pyenv 和 virtualenv 的目的感到困惑。更糟糕的是在 pyenv 中有一个 virtualenv 插件。

my questions are:

我的问题是:

  • what is the difference between pyenv and virtualenv?
  • Is there any difference in using pip command inside both pyenv and virtualenv?
  • what does this pyenv virutalenv do?
  • pyenv 和 virtualenv 有什么区别?
  • 在 pyenv 和 virtualenv 中使用 pip 命令有什么区别吗?
  • 这个 pyenv virutalenv 是做什么的?

your explanation with example will be highly appreciated.

您对示例的解释将不胜感激。

回答by Wade Williams

Edit: It's worth mentioning piphere as well, as condaand piphave similarities and differences that are relevant to this topic.

编辑:值得一提的pip这里为好,因为condapip有相似之处和有关这个话题的差异

pip: the Python Package Manager.

pip:Python 包管理器。

  • You might think of pipas the python equivalent of the ruby gemcommand
  • pipis not included with python by default.
  • You may install Python using homebrew, which will install pip automatically: brew install python
  • The final version of OSX did not include pip by default. To add pip to your mac system's version of python, you can sudo easy_install pip
  • You can find and publish python packages using PyPI: The Python Package Index
  • The requirements.txt file is comparable to the ruby gemfile
  • To create a requirements text file, pip freeze > requirements.txt
  • Note, at this point, we have python installed on our system, and we have created a requirements.txt file that outlines all of the python packages that have been installed on your system.
  • 你可能会认为piprubygem命令的 Python 等价物
  • pip默认情况下不包含在 python 中。
  • 你可以使用homebrew安装 Python ,它会自动安装 pip:brew install python
  • 默认情况下,OSX 的最终版本不包含 pip。要将 pip 添加到您的 mac 系统版本的 python,您可以sudo easy_install pip
  • 您可以使用PyPI查找和发布 Python 包:Python 包索引
  • requirements.txt 文件相当于 ruby gemfile
  • 要创建需求文本文件, pip freeze > requirements.txt
  • 请注意,此时,我们已经在系统上安装了 python,并且我们已经创建了一个 requirements.txt 文件,该文件概述了系统上已安装的所有 python 包。

pyenv: Python Version Manager

pyenv:Python 版本管理器

  • From the docs: pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. This project was forked from rbenv and ruby-build, and modified for Python.
  • Many folks hesitate to use python3.
  • If you need to use different versions of python, pyenvlets you manage this easily.
  • 来自文档pyenv 可让您轻松地在多个 Python 版本之间切换。它简单、不引人注目,并且遵循 UNIX 传统的单一用途工具,可以很好地完成一件事。这个项目是从 rbenv 和 ruby​​-build 派生出来的,并针对 Python 进行了修改。
  • 许多人对使用 python3 犹豫不决
  • 如果您需要使用不同版本的python,pyenv让您轻松管理。

virtualenv: Python Environment Manager.

virtualenv:Python 环境管理器。

  • From the docs: The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform's standard location is), it's easy to end up in a situation where you unintentionally upgrade an application that shouldn't be upgraded.
  • To create a virtualenv, simply invoke virtualenv ENV, where ENVis is a directory to place the new virtual environment.
  • To initialize the virtualenv, you need to source ENV/bin/activate. To stop using, simply call deactivate.
  • Once you activate the virtualenv, you might install all of a workspace's package requirements by running pip install -ragainst the project's requirements.txtfile.
  • 来自文档正在解决的基本问题是依赖项和版本之一,以及间接权限。假设您有一个需要 LibFoo 版本 1 的应用程序,但另一个应用程序需要版本 2。如何同时使用这两个应用程序?如果您将所有内容都安装到 /usr/lib/python2.7/site-packages(或任何您平台的标准位置)中,很容易导致您无意中升级了不应升级的应用程序。
  • 要创建virtualenv,只需调用virtualenv ENV,其中ENV是放置新虚拟环境的目录。
  • 要初始化virtualenv,您需要source ENV/bin/activate. 要停止使用,只需调用deactivate
  • 激活 后virtualenv,您可以通过pip install -r针对项目requirements.txt文件运行来安装工作区的所有包要求。

Anaconda: Package Manager + Environment Manager + Additional Scientific Libraries.

Anaconda:包管理器 + 环境管理器 + 附加科学库。

  • From the docs: Anaconda 4.2.0 includes an easy installation of Python (2.7.12, 3.4.5, and/or 3.5.2) and updates of over 100 pre-built and tested scientific and analytic Python packages that include NumPy, Pandas, SciPy, Matplotlib, and IPython, with over 620 more packages available via a simple conda install <packagename>
  • As a web developer, I haven't used Anaconda. It's ~3GB including all the packages.
  • There is a slimmed down minicondaversion, which seems like it could be a more simple option than using pip+ virtualenv, although I don't have experience using it personally.
  • While condaallows you to install packages, these packages are separate than PyPI packages, so you may still need to use pip additionally depending on the types of packages you need to install.
  • 来自文档Anaconda 4.2.0 包括 Python(2.7.12、3.4.5 和/或 3.5.2)的简单安装以及 100 多个预先构建和测试的科学和分析 Python 包的更新,其中包括 NumPy、Pandas 、SciPy、Matplotlib 和 IPython,还有 620 多个包可通过一个简单的conda install <packagename>
  • 作为 Web 开发人员,我没有使用过 Anaconda。包括所有软件包在内大约有 3GB。
  • 有一个精简miniconda版,虽然我个人没有使用它的经验,但它似乎比使用pip+更简单virtualenv
  • 虽然conda允许您安装包,但这些包与 PyPI 包是分开的,因此您可能仍然需要额外使用 pip,具体取决于您需要安装的包类型。

See also:

也可以看看: