简体   繁体   English

pyenv、virtualenv、anaconda有什么区别?

[英]What is the difference between pyenv, virtualenv, anaconda?

I am a ruby programmer trying to learn python. I am pretty familiar with pyenv since it is like a copy and paste from rbenv.我是一名 ruby 程序员,正在尝试学习 python。我对 pyenv 非常熟悉,因为它就像是从 rbenv 复制和粘贴。 Pyenv helps allow to have more than one version of python in a system and also to isolate the python without touching sensitive parts of system. Pyenv 有助于允许在一个系统中拥有多个版本的 python,并在不接触系统敏感部分的情况下隔离 python。

I suppose every python installation comes 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 a virtualenv plugin for pyenv.我想每个 python 安装都带有 pip package。我仍然不明白的是,那里有很多好的 python 库建议使用这个 virtualenv 和 anaconda。我什至可以找到 pyenv 的 virtualenv 插件。

Now I am getting confused with the purpose of these two pyenv and virtualenv.现在我对这两个 pyenv 和 virtualenv 的目的感到困惑。 worse inside pyenv there is a virtualenv plugin.更糟糕的是,在 pyenv 中有一个 virtualenv 插件。

My questions are:我的问题是:

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

Your explanation with example will be highly appreciated.非常感谢您的示例解释。

Edit: It's worth mentioning pip here as well, as conda and pip have similarities and differences that are relevant to this topic .编辑:这里也值得一提pip ,因为condapip有与此主题相关的异同

pip: the Python Package Manager. pip:Python 包管理器。

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

pyenv: Python Version Manager pyenv:Python 版本管理器

  • From the docs : pyenv lets you easily switch between multiple versions of Python. 来自文档pyenv 可让您轻松地在多个 Python 版本之间切换。 It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.它简单、不引人注目,并且遵循 UNIX 传统的单一用途工具,可以很好地完成一件事。 This project was forked from rbenv and ruby-build, and modified for Python.这个项目是从 rbenv 和 ruby​​-build 派生出来的,并针对 Python 进行了修改。
  • Many folks hesitate to use python3 .许多人对使用 python3 犹豫不决
  • If you need to use different versions of python, pyenv lets you manage this easily.如果您需要使用不同版本的 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?假设您有一个应用程序需要版本 1 的 LibFoo,但另一个应用程序需要版本 2。如何同时使用这两个应用程序? 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.如果您将所有内容都安装到 /usr/lib/python2.7/site-packages(或任何您平台的标准位置)中,很容易导致您无意中升级了不应升级的应用程序。
  • To create a virtualenv , simply invoke virtualenv ENV , where ENV is is a directory to place the new virtual environment.要创建virtualenv ,只需调用virtualenv ENV ,其中ENV是放置新虚拟环境的目录。
  • To initialize the virtualenv , you need to source ENV/bin/activate .要初始化virtualenv ,您需要source ENV/bin/activate To stop using, simply call deactivate .要停止使用,只需调用deactivate
  • Once you activate the virtualenv , you might install all of a workspace's package requirements by running pip install -r against the project's requirements.txt file.激活virtualenv ,您可以通过针对项目的requirements.txt文件运行pip install -r工作区的所有包要求。

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>来自文档Anaconda 4.2.0 包括 Python(2.7.12、3.4.5 和/或 3.5.2)的简单安装以及 100 多个预先构建和测试的科学和分析 Python 包的更新,其中包括 NumPy、Pandas 、SciPy、Matplotlib 和 IPython,通过简单的conda install <packagename>可提供 620 多个包
  • As a web developer, I haven't used Anaconda.作为 Web 开发人员,我没有使用过 Anaconda。 It's ~3GB including all the packages.包括所有软件包在内大约有 3GB。
  • There is a slimmed down miniconda version, which seems like it could be a more simple option than using pip + virtualenv , although I don't have experience using it personally.有一个精简的miniconda版本,虽然我个人没有使用它的经验,但它似乎比使用pip + virtualenv更简单。
  • While conda allows 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.虽然conda允许您安装软件包,但这些软件包与 PyPI 软件包是分开的,因此您可能仍需要额外使用 pip,具体取决于您需要安装的软件包类型。

See also:另见:

Simple analogy:简单的比喻:

  • pyenv ~ rbenv pyenv ~ rbenv
  • pip ~ bundler pip ~ 捆绑器
  • virtual env ~ gemset in rvm.虚拟环境 ~ rvm 中的 gemset。 This can be managed by bundler directly without gemset.这可以由 bundler 直接管理,无需 gemset。

Since I use python3 I prefer the python3 built-in virtual environment named venv .由于我使用 python3,我更喜欢名为venv的 python3 内置虚拟环境。 venv is simple and easy to use. venv简单易用。 I would recommend you to read its official docs.我建议你阅读它的官方文档。 The doc is short and concise.该文档简短明了。

In ruby, we don't really need a virtual environment because the bundler takes care of it.在 ruby​​ 中,我们并不真正需要虚拟环境,因为捆绑器会处理它。 Both virtual env and bundler are great, however, they have different solutions to solve the same problem. virtual env 和 bundler 都很棒,但是,它们有不同的解决方案来解决相同的问题。

Simple explanation: https://docs.conda.io/projects/conda/en/latest/commands.html#conda-vs-pip-vs-virtualenv-commands简单解释: https://docs.conda.io/projects/conda/en/latest/commands.html#conda-vs-pip-vs-virtualenv-commands

If you have used pip and virtualenv in the past, you can use conda to perform all of the same operations.如果您过去使用过 pipvirtualenv ,则可以使用conda执行所有相同的操作。

  • Pip is a package manager Pip 是 package 经理
  • virtualenv is an environment manager virtualenv 是一个环境管理器
  • Conda is both康达是两者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM