我是一个ruby程序员,正在学习python。我非常熟悉pyenv,因为它就像rbenv的复制和粘贴。Pyenv允许在一个系统中有多个版本的python,还可以在不触及系统敏感部分的情况下隔离python。

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

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

我的问题是:

pyenv和virtualenv的区别是什么? 在pyenv和virtualenv中使用pip命令有什么不同吗? pyenv virutalenv是做什么的?

请举例说明,我将不胜感激。


当前回答

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

如果您以前使用过pip和virtualenv,那么可以使用conda执行所有相同的操作。

Pip是一个包管理器 Virtualenv是一个环境管理器 Conda两者都有

其他回答

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

如果您以前使用过pip和virtualenv,那么可以使用conda执行所有相同的操作。

Pip是一个包管理器 Virtualenv是一个环境管理器 Conda两者都有

简单的类比:

Pyenv ~ rbenv PIP ~捆扎机 rvm中的虚拟环境。这可以由捆扎机直接管理,无需镶嵌。

因为我使用python3,所以我更喜欢python3内置的虚拟环境venv。Venv简单易用。我建议你看一下官方文件。这份文件短小精悍。

在ruby中,我们实际上不需要虚拟环境,因为绑定器会处理它。virtual env和bundler都很棒,但是,他们有不同的解决方案来解决相同的问题。

编辑:这里也值得一提的是pip,因为conda和pip有与本主题相关的相似点和不同点。

pip: Python包管理器。

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版本管理器

pyenv让你可以轻松地在多个Python版本之间切换。它简单、不引人注目,并且遵循UNIX传统,即只做一件事的单一用途工具。这个项目是从rbenv和ruby-build中派生出来的,并针对Python进行了修改。 许多人对使用python3犹豫不决。 如果您需要使用不同版本的python, pyenv可以让您轻松地进行管理。

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 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 is a commercial distribution of Python with the most popular python libraries, you are not permitted to use Anaconda in an organisation with more than 200 employees. 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.

参见:

Conda vs PIP vs virtualenv (anaconda文档部分) PIP和conda的区别(stackoverflow) virtualenv和pyenv的关系(stackoverflow)