venv、pyvenv、pyenv、virtualenv、virtualenvwrapper、pipenv 等有什么区别? [英] What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc?

查看:71
本文介绍了venv、pyvenv、pyenv、virtualenv、virtualenvwrapper、pipenv 等有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 3.3 在其标准库中包含新包 venv.它有什么作用,它与所有其他似乎与正则表达式匹配的包有什么不同 (py)?(v|virtual|pip)?env?

Python 3.3 includes in its standard library the new package venv. What does it do, and how does it differ from all the other packages that seem to match the regex (py)?(v|virtual|pip)?env?

推荐答案

初学者建议:

这是我对初学者的个人建议:从学习virtualenv开始和 pip,这些工具适用于 Python 2 和 3,并在各种情况,并在您开始需要它们时选择其他工具.

Recommendation for beginners:

This is my personal recommendation for beginners: start by learning virtualenv and pip, tools which work with both Python 2 and 3 and in a variety of situations, and pick up other tools once you start needing them.

  • virtualenv 是一个非常为 Python 库创建隔离的 Python 环境的流行工具.如果您不熟悉这个工具,我强烈建议您学习它,因为它是一个非常有用的工具,我将在本答案的其余部分与它进行比较.
  • virtualenv is a very popular tool that creates isolated Python environments for Python libraries. If you're not familiar with this tool, I highly recommend learning it, as it is a very useful tool, and I'll be making comparisons to it for the rest of this answer.

它的工作原理是在一个目录中安装一堆文件(例如:env/),然后修改 PATH 环境变量以使用自定义的 作为前缀>bin 目录(例如:env/bin/).pythonpython3 二进制文件的精确副本放置在此目录中,但 Python 被编程为首先在环境目录中查找与其路径相关的库.它不是 Python 标准库的一部分,但受到 PyPA(Python Packaging Authority)的正式祝福.激活后,您可以使用 pip 在虚拟环境中安装软件包.

It works by installing a bunch of files in a directory (eg: env/), and then modifying the PATH environment variable to prefix it with a custom bin directory (eg: env/bin/). An exact copy of the python or python3 binary is placed in this directory, but Python is programmed to look for libraries relative to its path first, in the environment directory. It's not part of Python's standard library, but is officially blessed by the PyPA (Python Packaging Authority). Once activated, you can install packages in the virtual environment using pip.

  • pyenv 使用隔离 Python 版本.例如,您可能想要针对 Python 2.7、3.6、3.7 和 3.8 测试您的代码,因此您需要一种在它们之间切换的方法.一旦激活,它会在 PATH 环境变量前面加上 ~/.pyenv/shims,其中有匹配 Python 命令的特殊文件(pythonpip).这些不是 Python 提供的命令的副本;它们是特殊的脚本,可以根据 PYENV_VERSION 环境变量、.python-version 文件或 ~/.pyenv/version 文件.pyenv 还使下载和安装多个 Python 版本的过程更容易,使用命令 pyenv install.

  • pyenv is used to isolate Python versions. For example, you may want to test your code against Python 2.7, 3.6, 3.7 and 3.8, so you'll need a way to switch between them. Once activated, it prefixes the PATH environment variable with ~/.pyenv/shims, where there are special files matching the Python commands (python, pip). These are not copies of the Python-shipped commands; they are special scripts that decide on the fly which version of Python to run based on the PYENV_VERSION environment variable, or the .python-version file, or the ~/.pyenv/version file. pyenv also makes the process of downloading and installing multiple Python versions easier, using the command pyenv install.

pyenv-virtualenvpyenvpyenv 同一作者的插件,允许你使用 pyenvvirtualenv同时方便.但是,如果您使用 Python 3.3 或更高版本,pyenv-virtualenv 将尝试运行 python -m venv(如果可用),而不是 virtualenv代码>.如果您不想要便利功能,您可以将 virtualenvpyenv 一起使用,而无需 pyenv-virtualenv.

pyenv-virtualenv is a plugin for pyenv by the same author as pyenv, to allow you to use pyenv and virtualenv at the same time conveniently. However, if you're using Python 3.3 or later, pyenv-virtualenv will try to run python -m venv if it is available, instead of virtualenv. You can use virtualenv and pyenv together without pyenv-virtualenv, if you don't want the convenience features.

virtualenvwrapper是一组对 virtualenv 的扩展(参见 docs).它为您提供了诸如 mkvirtualenvlssitepackages 之类的命令,尤其是用于在不同 virtualenv 目录之间切换的 workon.如果您需要多个 virtualenv 目录,此工具特别有用.

virtualenvwrapper is a set of extensions to virtualenv (see docs). It gives you commands like mkvirtualenv, lssitepackages, and especially workon for switching between different virtualenv directories. This tool is especially useful if you want multiple virtualenv directories.

pyenv-virtualenvwrapperpyenvpyenv 同一作者的插件,用于方便地将 virtualenvwrapper 集成到 pyenv 中.

pyenv-virtualenvwrapper is a plugin for pyenv by the same author as pyenv, to conveniently integrate virtualenvwrapper into pyenv.

pipenv旨在将 Pipfilepipvirtualenv 组合成一个命令行命令.virtualenv 目录通常放在 ~/.local/share/virtualenvs/XXX 中,其中 XXX 是项目路径的哈希值目录.这与 virtualenv 不同,后者的目录通常位于当前工作目录中.pipenv 旨在用于开发 Python 应用程序(而不是库).pipenv 有替代品,比如poetry,这里就不一一列举了,因为这个问题只针对同名的包.

pipenv aims to combine Pipfile, pip and virtualenv into one command on the command-line. The virtualenv directory typically gets placed in ~/.local/share/virtualenvs/XXX, with XXX being a hash of the path of the project directory. This is different from virtualenv, where the directory is typically in the current working directory. pipenv is meant to be used when developing Python applications (as opposed to libraries). There are alternatives to pipenv, such as poetry, which I won't list here since this question is only about the packages that are similarly named.

  • pyvenv 是 Python 3 附带的脚本,但 在 Python 3.6 中弃用,因为它有问题(更不用说令人困惑的名称了).在 Python 3.6+ 中,完全等效的是 python3 -m venv.

  • pyvenv is a script shipped with Python 3 but deprecated in Python 3.6 as it had problems (not to mention the confusing name). In Python 3.6+, the exact equivalent is python3 -m venv.

venv 是 Python 3 附带的包,您可以使用 python3 -m venv 运行它(尽管出于某种原因,某些发行版将其分离为单独的发行版包,例如 python3-venv 在 Ubuntu/Debian 上).它与 virtualenv 的用途相同,但只有其功能的一个子集(在此处查看比较).virtualenv 仍然比 venv 更受欢迎,尤其是因为前者同时支持 Python 2 和 3.

venv is a package shipped with Python 3, which you can run using python3 -m venv (although for some reason some distros separate it out into a separate distro package, such as python3-venv on Ubuntu/Debian). It serves the same purpose as virtualenv, but only has a subset of its features (see a comparison here). virtualenv continues to be more popular than venv, especially since the former supports both Python 2 and 3.

这篇关于venv、pyvenv、pyenv、virtualenv、virtualenvwrapper、pipenv 等有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆