问题:pyenv,virtualenv,anaconda有什么区别?

我是一个尝试学习python的红宝石程序员。我很喜欢pyenv,因为它就像来自rbenv的复制和粘贴一样。Pyenv帮助在系统中拥有多个版本的python,并且无需隔离系统的敏感部分即可隔离python。

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

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

我的问题是:

  • pyenv和virtualenv有什么区别?
  • 在pyenv和virtualenv中使用pip命令有什么区别吗?
  • pyenv virutalenv做什么?

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

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.

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.

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

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?

your explanation with example will be highly appreciated.


回答 0

编辑:pip这里也值得一提,conda并且pip具有与该主题相关的异同

pip:Python软件包管理器。

  • 您可能将其pip视为ruby gem命令的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版本管理器

  • 从文档 pyenv可以轻松在多个版本的Python之间切换。它简单,简单,遵循UNIX的一站式工具的传统,可以很好地完成一件事。该项目是从rbenv和ruby-build分叉的,并针对Python进行了修改。
  • 很多人 不愿使用python3
  • 如果您需要使用其他版本的python,则pyenv可以轻松进行管理。

virtualenv:Python环境管理器。

  • 从文档要解决的基本问题是依赖项和版本之一以及间接权限。假设您有一个需要使用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:程序包经理+环境经理+其他科学图书馆。

  • 来自文档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。

也可以看看:

Edit: It’s worth mentioning pip here as well, as conda and pip have similarities and differences that are relevant to this topic.

pip: the Python Package Manager.

  • You might think of pip as the python equivalent of the ruby gem command
  • pip is 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.

pyenv: Python Version Manager

  • 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, pyenv lets you manage this easily.

virtualenv: Python Environment Manager.

  • 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 ENV is 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 -r against the project’s requirements.txt file.

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

  • 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 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.
  • 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.

See also:


回答 1

简单类比:

  • pyenv〜rbenv
  • 点〜捆绑器
  • 虚拟环境〜rvm中的gemset。可以由捆绑器直接管理,而无需使用gemset。

由于我使用python3,因此我更喜欢名为venv的python3内置虚拟环境。venv简单易用。我建议您阅读其官方文档。该文档简短明了。

在ruby中,我们实际上并不需要虚拟环境,因为捆绑程序会处理它。虚拟环境和捆绑程序都很棒,但是它们的概念不同,但是它们试图解决相同的问题。

Simple analogy:

  • pyenv ~ rbenv
  • pip ~ bundler
  • virtual env ~ gemset in rvm. This can be managed by bundler directly without gemset.

Since I use python3 I prefer the python3 built-in virtual environment named venv. venv is simple and easy to use. 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. Both virtual env and bundler are great, however, they have different solutions to solve the same problem.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。