简体   繁体   English

venv、pyvenv、pyenv、virtualenv、virtualenvwrapper、pipenv 等有什么区别?

[英]What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc?

Python 3.3 includes in its standard library the new package venv . Python 3.3 在其标准库中包含了新的包venv What does it do, and how does it differ from all the other packages that match the regex (py)?(v|virtual|pip)?env ?它有什么作用,它与匹配正则表达式(py)?(v|virtual|pip)?env的所有其他包有何不同?

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.这是我对初学者的个人建议:从学习virtualenvpip开始,这些工具可以在 Python 2 和 3 以及各种情况下使用,一旦你开始需要它们,就选择其他工具。

Now on to the answer to the question: what is the difference between these simalarly named things: venv, virtualenv, etc?现在回答这个问题:这些类似命名的事物之间有什么区别:venv、virtualenv 等?

PyPI packages not in the standard library: PyPI 包不在标准库中:

  • virtualenv is a very popular tool that creates isolated Python environments for Python libraries. virtualenv是一个非常流行的工具,可以为 Python 库创建隔离的 Python 环境。 If you're not familiar with this tool, I highly recommend learning it, as it is a very useful tool.如果您不熟悉此工具,我强烈建议您学习它,因为它是一个非常有用的工具。

    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/ ).它的工作原理是在一个目录中安装一堆文件(例如: env/ ),然后修改PATH环境变量以使用自定义bin目录作为前缀(例如: 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. pythonpython3二进制文件的精确副本放置在此目录中,但 Python 被编程为首先在环境目录中查找与其路径相关的库。 It's not part of Python's standard library, but is officially blessed by the PyPA (Python Packaging Authority).它不是 Python 标准库的一部分,但得到了 PyPA(Python Packaging Authority)的正式祝福。 Once activated, you can install packages in the virtual environment using pip .激活后,您可以使用pip在虚拟环境中安装软件包。

  • pyenv is used to isolate Python versions. pyenv用于隔离 Python 版本。 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.例如,您可能希望针对 Python 2.7、3.6、3.7 和 3.8 测试您的代码,因此您需要一种在它们之间切换的方法。 Once activated, it prefixes the PATH environment variable with ~/.pyenv/shims , where there are special files matching the Python commands ( python , pip ).激活后,它会在PATH环境变量前面加上~/.pyenv/shims ,其中有与 Python 命令( pythonpip )匹配的特殊文件。 These are not copies of the Python-shipped commands;这些不是 Python 提供的命令的副本; 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_VERSION环境变量、 .python-version文件或~/.pyenv/version文件即时决定运行哪个 Python 版本。 pyenv also makes the process of downloading and installing multiple Python versions easier, using the command pyenv install . pyenv还使用命令pyenv install使下载和安装多个 Python 版本的过程更容易。

  • 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. pyenv-virtualenv是与pyenv同一作者的pyenv插件,让您可以方便地同时使用pyenvvirtualenv 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 .但是,如果您使用的是 Python 3.3 或更高版本, pyenv-virtualenv将尝试运行python -m venv如果可用),而不是virtualenv You can use virtualenv and pyenv together without pyenv-virtualenv , if you don't want the convenience features.如果您不想要便利功能,则可以在没有pyenv-virtualenv情况下一起使用virtualenvpyenv

  • virtualenvwrapper is a set of extensions to virtualenv (see docs ).virtualenvwrappervirtualenv的一组扩展(参见docs )。 It gives you commands like mkvirtualenv , lssitepackages , and especially workon for switching between different virtualenv directories.它为您提供mkvirtualenvlssitepackages等命令,尤其workon用于在不同virtualenv目录之间切换的工作。 This tool is especially useful if you want multiple virtualenv directories.如果您需要多个virtualenv目录,此工具特别有用。

  • pyenv-virtualenvwrapper is a plugin for pyenv by the same author as pyenv , to conveniently integrate virtualenvwrapper into pyenv . pyenv-virtualenvwrapper是与pyenv同一作者的pyenv插件,可以方便地将virtualenvwrapper集成到pyenv中。

  • pipenv aims to combine Pipfile , pip and virtualenv into one command on the command-line. pipenv旨在将Pipfilepipvirtualenv组合成命令行上的一个命令。 The virtualenv directory typically gets placed in ~/.local/share/virtualenvs/XXX , with XXX being a hash of the path of the project directory. virtualenv目录通常放置在~/.local/share/virtualenvs/XXX中,其中XXX是项目目录路径的哈希值。 This is different from virtualenv , where the directory is typically in the current working directory.这与virtualenv不同,其中目录通常位于当前工作目录中。 pipenv is meant to be used when developing Python applications (as opposed to libraries). pipenv旨在用于开发 Python 应用程序(而不是库)。 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. pipenv有其他替代品,例如poetry ,我不会在此处列出,因为这个问题仅与名称相似的包有关。

Standard library:标准库:

  • pyvenv (not to be confused with pyenv in the previous section) is a script shipped with Python 3.3 to 3.7. pyvenv (不要与上一节中的pyenv混淆)是 Python 3.3 到 3.7 附带的脚本。 It was removed from Python 3.8 as it had problems (not to mention the confusing name).从 Python 3.8中删除,因为它有问题(更不用说令人困惑的名称)。 Running python3 -m venv has exactly the same effect as pyvenv .运行python3 -m venv的效果与pyvenv

  • 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). venv是 Python 3 附带的一个包,您可以使用python3 -m venv运行它(尽管出于某种原因,一些发行版将其分离到一个单独的发行版包中,例如 Ubuntu/Debian 上的python3-venv )。 It serves the same purpose as virtualenv , but only has a subset of its features ( see a comparison here ).它的用途与virtualenv相同,但只有一部分功能(请参阅此处的比较)。 virtualenv continues to be more popular than venv , especially since the former supports both Python 2 and 3. virtualenv继续比venv更受欢迎,特别是因为前者同时支持 Python 2 和 3。

I would just avoid the use of virtualenv after Python3.3+ and instead use the standard shipped library venv .我只是避免在 Python3.3+ 之后使用virtualenv ,而是使用标准发布的库venv To create a new virtual environment you would type:要创建一个新的虚拟环境,您可以键入:

$ python3 -m venv <MYVENV>  

virtualenv tries to copy the Python binary into the virtual environment's bin directory. virtualenv尝试将 Python 二进制文件复制到虚拟环境的 bin 目录中。 However it does not update library file links embedded into that binary, so if you build Python from source into a non-system directory with relative path names, the Python binary breaks.但是,它不会更新嵌入到该二进制文件中的库文件链接,因此如果您将 Python 从源代码构建到具有相对路径名的非系统目录中,则 Python 二进制文件会中断。 Since this is how you make a copy distributable Python, it is a big flaw.由于这是您制作副本可分发 Python 的方式,因此这是一个很大的缺陷。 BTW to inspect embedded library file links on OS X, use otool .顺便说一句,要检查 OS X 上的嵌入式库文件链接,请使用otool For example from within your virtual environment, type:例如,在您的虚拟环境中,键入:

$ otool -L bin/python
python:
    @executable_path/../Python (compatibility version 3.4.0, current version 3.4.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)

Consequently I would avoid virtualenvwrapper and pipenv .因此,我会避免使用virtualenvwrapperpipenv pyvenv is deprecated. pyvenv已弃用。 pyenv seems to be used often where virtualenv is used but I would stay away from it also since I think venv also does what pyenv is built for. pyenv似乎经常在使用virtualenv的地方使用,但我也会远离它,因为我认为venv也可以完成pyenv的构建。

venv creates virtual environments in the shell that are fresh and sandboxed , with user-installable libraries , and it's multi-python safe . venv在 shell 中创建的和沙盒的虚拟环境,带有用户可安装的库,并且它是多 python 安全的。

Fresh : because virtual environments only start with the standard libraries that ship with python, you have to install any other libraries all over again with pip install while the virtual environment is active.新鲜:因为虚拟环境仅从 python 附带的标准库开始,所以您必须在虚拟环境处于活动状态时使用pip install重新安装任何其他库。

Sandboxed : because none of these new library installs are visible outside the virtual environment, so you can delete the whole environment and start again without worrying about impacting your base python install.沙盒:因为这些新的库安装在虚拟环境之外都不可见,所以您可以删除整个环境并重新开始,而不必担心影响您的基本 python 安装。

User-installable libraries : because the virtual environment's target folder is created without sudo in some directory you already own, so you won't need sudo permissions to install libraries into it.用户可安装的库:因为虚拟环境的目标文件夹是在您已经拥有的某个目录中创建的而没有sudo ,因此您不需要sudo权限即可将库安装到其中。

multi-python safe : because when virtual environments activate, the shell only sees the python version (3.4, 3.5 etc.) that was used to build that virtual environment. multi-python safe :因为当虚拟环境激活时,shell 只能看到用于构建该虚拟环境的 python 版本(3.4、3.5 等)。

pyenv is similar to venv in that it lets you manage multiple python environments. pyenvvenv类似,它允许您管理多个 python 环境。 However with pyenv you can't conveniently rollback library installs to some start state and you will likely need admin privileges at some point to update libraries.但是,使用pyenv ,您不能方便地将库安装回滚到某个启动状态,并且您可能在某些时候需要admin权限来更新库。 So I think it is also best to use venv .所以我认为最好使用venv

In the last couple of years I have found many problems in build systems (emacs packages, python standalone application builders, installers...) that ultimately come down to issues with virtualenv .在过去的几年里,我在构建系统(emacs 包、python 独立应用程序构建器、安装程序...)中发现了许多问题,最终归结为virtualenv的问题。 I think python will be a better platform when we eliminate this additional option and only use venv .我认为当我们消除这个附加选项并且只使用venv时,python 将是一个更好的平台。

EDIT: Tweet of the BDFL,编辑:BDFL 的推文,

I use venv (in the stdlib) and a bunch of shell aliases to quickly switch.我使用 venv(在标准库中)和一堆 shell 别名来快速切换。

— Guido van Rossum (@gvanrossum) October 22, 2020 — Guido van Rossum (@gvanrossum) 2020 年 10 月 22 日

UPDATE 20200825:更新 20200825:

Added below " Conclusion " paragraph在“结论”段落下方添加

I've went down the pipenv rabbit hole ( it's a deep and dark hole indeed... ) and since the last answer is over 2 years ago , felt it was useful to update the discussion with the latest developments on the Python virtual envelopes topic I've found.我已经进入了pipenv兔子洞(它确实是一个又深又黑的洞...... )并且由于最后一个答案是 2 年前,我觉得用 Python 虚拟信封主题的最新发展来更新讨论很有用我找到了。

DISCLAIMER:免责声明:

This answer is NOT about continuing the raging debate about the merits of pipenv versus venv as envelope solutions- I make no endorsement of either .这个答案不是关于继续关于pipenvvenv作为信封解决方案的优点的激烈辩论 -我不认可任何一个 It's about PyPA endorsing conflicting standards and how future development of virtualenv promises to negate making an either/or choice between them at all.这是关于PyPA认可相互冲突的标准,以及virtualenv的未来发展如何承诺完全否定在它们之间做出非此即彼的选择。 I focused on these two tools precisely because they are the anointed ones by PyPA .我专注于这两个工具正是因为它们是PyPA 指定的工具。

venv venv

As the OP notes, venv is a tool for virtualizing environments.正如 OP 所指出的, venv是一种用于虚拟化环境的工具。 NOT a third party solution, but native tool.不是第三方解决方案,而是原生工具。 PyPA endorses venv for creating VIRTUAL ENVELOPES : " Changed in version 3.5: The use of venv is now recommended for creating virtual environments ". PyPA认可venv用于创建虚拟信封:“在 3.5 版中更改:现在建议使用 venv 来创建虚拟环境”。

pipenv管道

pipenv - like venv - can be used to create virtual envelopes but additionally rolls-in package management and vulnerability checking functionality. pipenv - 与venv类似 - 可用于创建虚拟信封,但另外还包含包管理和漏洞检查功能。 Instead of using requirements.txt , pipenv delivers package management via Pipfile . pipenv不使用requirements.txt ,而是通过pipenv提供包管理。 As PyPA endorses pipenv for PACKAGE MANAGEMENT , that would seem to imply pipfile is to supplant requirements.txt .由于PyPA认可 pipenv 用于PACKAGE MANAGEMENT ,这似乎意味着pipfile将取代requirements.txt

HOWEVER : pipenv uses virtualenv as its tool for creating virtual envelopes, NOT venv which is endorsed by PyPA as the go-to tool for creating virtual envelopes.但是pipenv使用virtualenv作为创建虚拟信封的工具,而不是venv ,它被PyPA认可为创建虚拟信封的首选工具。

Conflicting Standards:冲突标准:

So if settling on a virtual envelope solution wasn't difficult enough, we now have PyPA endorsing two different tools which use different virtual envelope solutions.因此,如果确定虚拟信封解决方案还不够困难,我们现在有PyPA支持两种使用不同虚拟信封解决方案的不同工具。 The raging Github debate on venv vs virtualenv which highlights this conflict can be found here .可以在这里找到关于venv 与 virtualenv的激烈争论,突出了这种冲突。

Conflict Resolution:解决冲突:

The Github debate referenced in above link has steered virtualenv development in the direction of accommodating venv in future releases :上述链接中引用的 Github 辩论引导virtualenv开发朝着在未来版本中适应venv的方向发展:

prefer built-in venv: if the target python has venv we'll create the environment using that (and then perform subsequent operations on that to facilitate other guarantees we offer)更喜欢内置 venv:如果目标 python 有 venv,我们将使用它创建环境(然后对其执行后续操作以促进我们提供的其他保证)

Conclusion:结论:

So it looks like there will be some future convergence between the two rival virtual envelope solutions, but as of now pipenv - which uses virtualenv - varies materially from venv .因此,看起来这两种竞争的虚拟信封解决方案之间将会有一些未来的融合,但到目前为止,使用virtualenvpipenvvenv有很大的不同。

Given the problems pipenv solves and the fact that PyPA has given its blessing, it appears to have a bright future.鉴于pipenv解决的问题以及PyPA的支持,它似乎有一个光明的未来。 And if virtualenv delivers on its proposed development objectives, choosing a virtual envelope solution should no longer be a case of either pipenv OR venv .如果virtualenv实现了它提出的开发目标,那么选择一个虚拟信封解决方案应该不再是pipenvvenv的情况。

Update 20200825 :更新 20200825

An oft repeated criticism of Pipenv I saw when producing this analysis was that it was not actively maintained.在进行此分析时,我经常看到对Pipenv的反复批评是它没有得到积极的维护。 Indeed, what's the point of using a solution whose future could be seen questionable due to lack of continuous development?确实,使用一个由于缺乏持续开发而未来可能会受到质疑的解决方案有什么意义呢? After a dry spell of about 18 months, Pipenv is once again being actively developed.在经历了大约 18 个月的枯竭期后, Pipenv再次被积极开发。 Indeed, large and material updates have since been released .事实上,自那以后已经发布了大量的重大更新。

Let's start with the problems these tools want to solve:让我们从这些工具想要解决的问题开始:

My system package manager don't have the Python versions I wanted or I want to install multiple Python versions side by side, Python 3.9.0 and Python 3.9.1, Python 3.5.3, etc我的系统包管理器没有我想要的 Python 版本,或者我想并排安装多个 Python 版本,Python 3.9.0 和 Python 3.9.1、Python 3.5.3 等

Then use pyenv.然后使用 pyenv。

I want to install and run multiple applications with different, conflicting dependencies.我想安装和运行具有不同的、相互冲突的依赖项的多个应用程序。

Then use virtualenv or venv.然后使用 virtualenv 或 venv。 These are almost completely interchangeable, the difference being that virtualenv supports older python versions and has a few more minor unique features, while venv is in the standard library.这些几乎是完全可以互换的,不同之处在于 virtualenv 支持较旧的 python 版本并具有一些更小的独特功能,而 venv 在标准库中。

I'm developing an /application/ and need to manage my dependencies, and manage the dependency resolution of the dependencies of my project.我正在开发 /application/ 并且需要管理我的依赖项,并管理我的项目依赖项的依赖项解析。

Then use pipenv or poetry.然后使用 pipenv 或诗歌。

I'm developing a /library/ or a /package/ and want to specify the dependencies that my library users need to install我正在开发 /library/ 或 /package/ 并希望指定我的库用户需要安装的依赖项

Then use setuptools.然后使用设置工具。

I used virtualenv, but I don't like virtualenv folders being scattered around various project folders.我使用了 virtualenv,但我不喜欢 virtualenv 文件夹分散在各种项目文件夹中。 I want a centralised management of the environments and some simple project management我想要集中管理环境和一些简单的项目管理

Then use virtualenvwrapper.然后使用 virtualenvwrapper。 Variant: pyenv-virtualenvwrapper if you also use pyenv.变体:pyenv-virtualenvwrapper 如果你也使用 pyenv。


Not recommended不建议

  • pyvenv. pyvenv。 This is deprecated, use venv or virtualenv instead.这已弃用,请改用 venv 或 virtualenv。 Not to be confused with pipenv or pyenv.不要与 pipenv 或 pyenv 混淆。

Jan 2020 Update 2020 年 1 月更新

@Flimm has explained all the differences very well. @Flimm 很好地解释了所有差异。 Generally, we want to know the difference between all tools because we want to decide what's best for us.通常,我们想知道所有工具之间的区别,因为我们想决定什么最适合我们。 So, the next question would be: which one to use?那么,下一个问题是:使用哪一个? I suggest you choose one of the two official ways to manage virtual environments:我建议您选择以下两种官方方式之一来管理虚拟环境:

  • pyenv - manages different python versions, pyenv - 管理不同的 python 版本,
  • all others - create virtual environment (which has isolated python version and installed "requirements"),所有其他人-创建虚拟环境(具有隔离的python版本并安装了“要求”),

pipenv want combine all, in addition to previous it installs "requirements" (into the active virtual environment or create its own if none is active) pipenv想要结合所有,除了以前它安装“需求”(进入活动的虚拟环境,如果没有活动则创建自己的)

So maybe you will be happy with pipenv only.所以也许你只会对 pipenv 感到满意。

But I use: pyenv + pyenv-virtualenvwrapper, + pipenv (pipenv for installing requirements only).但我使用:pyenv + pyenv-virtualenvwrapper,+ pipenv(仅用于安装要求的 pipenv)。

In Debian:在 Debian 中:

  1. apt install libffi-dev

  2. install pyenv based on https://www.tecmint.com/pyenv-install-and-manage-multiple-python-versions-in-linux/ , but..根据https://www.tecmint.com/pyenv-install-and-manage-multiple-python-versions-in-linux/安装 pyenv,但是..

  3. .. but instead of pyenv-virtualenv install pyenv-virtualenvwrapper (which can be standalone library or pyenv plugin, here the 2nd option): .. 但不是 pyenv-virtualenv 安装 pyenv-virtualenvwrapper (可以是独立库或 pyenv 插件,这里是第二个选项):

     $ pyenv install 3.9.0 $ git clone https://github.com/pyenv/pyenv-virtualenvwrapper.git $(pyenv root)/plugins/pyenv-virtualenvwrapper # inside ~/.bashrc add: # export $VIRTUALENVWRAPPER_PYTHON="/usr/bin/python3" $ source ~/.bashrc $ pyenv virtualenvwrapper

Then create virtual environments for your projects (workingdir must exist):然后为您的项目创建虚拟环境(workingdir 必须存在):

pyenv local 3.9.0  # to prevent 'interpreter not found' in mkvirtualenv
python -m pip install --upgrade pip setuptools wheel
mkvirtualenv <venvname> -p python3.9 -a <workingdir>

and switch between projects:并在项目之间切换:

workon <venvname>
python -m pip install --upgrade pip setuptools wheel pipenv

Inside a project I have the file requirements.txt, without fixing the versions inside (if some version limitation is not neccessary).在一个项目中,我有文件 requirements.txt,没有修复里面的版本(如果不需要某些版本限制)。 You have 2 possible tools to install them into the current virtual environment: pip-tools or pipenv .您有 2 个可能的工具可以将它们安装到当前的虚拟环境中: pip-toolspipenv Lets say you will use pipenv:假设您将使用 pipenv:

pipenv install -r requirements.txt

this will create Pipfile and Pipfile.lock files, fixed versions are in the 2nd one.这将创建 Pipfile 和 Pipfile.lock 文件,固定版本在第二个。 If you want reinstall somewhere exactly same versions then (Pipfile.lock must be present):如果您想在完全相同版本的地方重新安装,那么(Pipfile.lock 必须存在):

pipenv install

Remember that Pipfile.lock is related to some Python version and need to be recreated if you use a different one.请记住,Pipfile.lock 与某些 Python 版本相关,如果您使用其他版本,则需要重新创建。

As you see I write requirements.txt.如您所见,我编写了 requirements.txt。 This has some problems: You must remove a removed package from Pipfile too.这有一些问题:您也必须从 Pipfile 中删除已删除的包。 So writing Pipfile directly is probably better.所以直接写Pipfile可能会更好。

So you can see I use pipenv very poorly.所以你可以看到我对 pipenv 的使用非常糟糕。 Maybe if you will use it well, it can replace everything?也许如果你用得好,它可以代替一切?

EDIT 2021.01 : I have changed my stack to: pyenv + pyenv-virtualenvwrapper + poetry .编辑 2021.01 :我已将堆栈更改为: pyenv + pyenv-virtualenvwrapper + poetry Ie. IE。 I use no apt or pip installation of virtualenv or virtualenvwrapper, and instead I install pyenv 's plugin pyenv-virtualenvwrapper .我不使用 virtualenv 或 virtualenvwrapper 的 apt 或 pip 安装,而是安装pyenv的插件pyenv-virtualenvwrapper This is easier way.这是更简单的方法。

Poetry is great for me: Poetry对我来说很棒:

poetry add <package>   # install single package
poetry remove <package>
poetry install   # if you remove poetry.lock poetry will re-calculate versions

As a Python newcomer this question frustrated me endlessly and confused me for months.作为一个 Python 新手,这个问题让我无休止地沮丧,让我困惑了几个月。 Which virtual environment and package manager(s) should I invest in learning when I know that I will be using it for years to come?当我知道我将在未来几年使用它时,我应该投资学习哪个虚拟环境和包管理器?

The best article answering this vexing question is https://jakevdp.github.io/blog/2016/08/25/conda-myths-and-misconceptions/ by Jake Vanderplas.回答这个棘手问题的最佳文章是 Jake Vanderplas 的https://jakevdp.github.io/blog/2016/08/25/conda-myths-and-misconceptions/ Although a few years old, it provides practical answers and the history of Python package and virtual environment managers from the trenches as these state-of-the-art was developing.尽管已有几年历史,但它提供了实用的答案以及 Python 包和虚拟环境管理器在这些最先进技术的发展过程中的历史。

It was particularly frustrating for me in the data science and "big data cloud computing" communities, because conda is widely used as a virtual environment manager and full function package manager for Python and JavaScript, SQL, Java, HTML5, and Jupyter Notebooks.在数据科学和“大数据云计算”社区中,我尤其感到沮丧,因为 conda 被广泛用作 Python 和 JavaScript、SQL、Java、HTML5 和 Jupyter Notebooks 的虚拟环境管理器和全功能包管理器。

So why use pip at all, when conda does everything that pip and venv variants do?那么,当 conda 完成 pip 和 venv 变体所做的一切时,为什么还要使用 pip 呢?

The answer is, "because you MUST use pip if a conda package is simply not available."答案是,“因为如果 conda 包根本不可用,您必须使用 pip。” Many times a required package is only available in pip format and there is no easy solution but to use pip.很多时候,所需的包仅以 pip 格式提供,没有简单的解决方案,只能使用 pip。 You can learn to use conda build but if you are not the package maintainer, then you must convince the package owner to generate a conda package for each new release (or do it yourself.)您可以学习使用conda build ,但如果您不是包维护者,那么您必须说服包所有者为每个新版本生成一个 conda 包(或自己做。)

These pip-based packages differ along many important and practical dimensions:这些基于 pip 的软件包在许多重要和实用的方面有所不同:

  • stability稳定
  • maturity到期
  • complexity复杂
  • active support (versus dying or dead)积极支持(相对于死亡或死亡)
  • levels of adoption near the Python ecosystem "core" versus "on the fringes" (ie, integrated into Python.org distro) Python 生态系统“核心”与“边缘”(即集成到 Python.org 发行版)附近的采用水平
  • easy to figure out and use (for beginners)易于理解和使用(适合初学者)

I will answer your question for two packages from dimension of package maturity and stability.我将从包成熟度和稳定性的维度回答你关于两个包的问题。

venv and virtualenv are the most mature, stability, and community support. venv 和 virtualenv 是最成熟、最稳定、最受社区支持的。 From the online documentation you can see that virtualenv is in version 20.x as of today.从在线文档中,您可以看到 virtualenv 截至今天的版本为 20.x。 virtualenv虚拟环境

virtualenv is a tool to create isolated Python environments. virtualenv 是一个创建隔离 Python 环境的工具。 Since Python 3.3, a subset of it has been integrated into the standard library under the venv module.从 Python 3.3 开始,它的一个子集被集成到标准库的 venv 模块下。 The venv module does not offer all features of this library, to name just a few more prominent: venv 模块不提供这个库的所有特性,仅举几个比较突出的例子:

 is slower (by not having the app-data seed method), is not as extendable, cannot create virtual environments for arbitrarily installed python versions (and automatically discover these), is not upgrade-able via pip, does not have as rich programmatic API (describe virtual environments without creating them).

virtualenvwrapper is set of scripts to help people use virtualenv (it is a "wrapper" that not well-maintained, its last update was in 2019. virtualenvwrapper virtualenvwrapper 是一组帮助人们使用 virtualenv 的脚本(它是一个维护不善的“包装​​器”,它的最后一次更新是在 2019 年。virtualenvwrapper

My recommendation is to avoid ALL pip virtual environments whenever possible.我的建议是尽可能避免使用所有 pip 虚拟环境。 Use conda instead.改用 conda。 Conda provides a unified approach. Conda 提供了一种统一的方法。 It is maintained by teams of professional open source developers and has a reputable company providing funding and a commercially supported version.它由专业的开源开发人员团队维护,并有一家信誉良好的公司提供资金和商业支持的版本。 The teams that maintain pip, venv, virtualenv, pipenv, and many other pip variants have limited resources by comparison.相比之下,维护 pip、venv、virtualenv、pipenv 和许多其他 pip 变体的团队资源有限。 The pip virtual environment plurality is frustrating for beginners. pip 虚拟环境的多样性对于初学者来说是令人沮丧的。 The pip-based virtual environment tools complexity, fragmentation, fringe and unsupported packages, and wildly inconsistent support drove me to use conda.基于 pip 的虚拟环境工具的复杂性、碎片化、边缘和不受支持的包以及极其不一致的支持促使我使用 conda。 For data science work, my recommendation is that to use a pip-based virtual environment manager as a last resort when conda packages do not exist.对于数据科学工作,我的建议是在 conda 包不存在时使用基于 pip 的虚拟环境管理器作为最后的手段。

The differences between the venv variants still scare me because my time is limited to learn new packages. venv 变体之间的差异仍然让我感到害怕,因为我学习新软件包的时间有限。 pipenv, venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, poetry, and others have dozens of differences and complexities that take days to understand. pipenv、venv、pyvenv、pyenv、virtualenv、virtualenvwrapper、诗歌和其他有几十个差异和复杂性,需要几天时间才能理解。 I hate going down a path and find support for a package goes belly-up when a maintainer resigns (or gets too busy to maintain it).我讨厌走上一条路,当维护者辞职(或太忙而无法维护它)时,对一个包的支持就会崩溃。 I just need to get my job done.我只需要完成我的工作。

In the spirit of being helpful, here are a few links to help you dive in over your head, but not get lost in Dante's Inferno (re: pip).本着乐于助人的精神,这里有一些链接可以帮助您深入了解,但不要迷失在但丁的地狱(re:pip)中。

A Guide to Python's Virtual Environments Python 虚拟环境指南

Choosing "core" Python packages to invest in for your career (long-term), versus getting a job done short term) is important.选择“核心”Python 包来投资你的职业(长期),而不是短期完成工作)很重要。 However, it is a business analysis question.但是,这是一个业务分析问题。 Are you trying to simply get a task done, or a professional software engineer who builds scalable performant systems that require the least amount of maintenance effort over time?您是想简单地完成一项任务,还是一个专业的软件工程师构建可扩展的高性能系统,随着时间的推移需要最少的维护工作? IMHO, conda will take you to the latter place more easily than dealing with pip-plurality problems.恕我直言,conda 比处理 pip-plurality 问题更容易将您带到后者。 conda is still missing 1-step pip-package migration tools that make this a moot question. conda 仍然缺少 1 步 pip-package 迁移工具,这使得这成为一个没有实际意义的问题。 If we could simply convert pip packages into conda packages then pypi.org and conda-forge could be merged.如果我们可以简单地将 pip 包转换为 conda 包,那么 pypi.org 和 conda-forge 可以合并。 Pip is necessary because conda packages are not (yet) universal. Pip 是必要的,因为 conda 包(还)不是通用的。 Many Python programmers are either too lazy to create conda packages, or they only program in Python and don't need conda's language-agnostic / multi-lingual support.许多 Python 程序员要么懒得创建 conda 包,要么只用 Python 编程,不需要 conda 的语言无关/多语言支持。

conda has been a god-send for me, because it supports cloud software engineering and data science's need for multilingual support of JavaScript, SQL, and Jupyter Notebook extensions, and conda plays well within Docker and other cloud-native environments. conda 对我来说是天赐之物,因为它支持云软件工程和数据科学对 JavaScript、SQL 和 Jupyter Notebook 扩展的多语言支持的需求,并且 conda 在 Docker 和其他云原生环境中运行良好。 I encourage you to learn and master conda, which will enable you to side-step many complex questions that pip-based tools may never answer.我鼓励您学习和掌握 conda,这将使您能够回避许多基于 pip 的工具可能永远无法回答的复杂问题。

Keep it simple!把事情简单化! I need one package that does 90% of what I need and guidance and workarounds for the 10% remaining edge cases.我需要一个包来完成我需要的 90% 的工作,并为剩下的 10% 的边缘情况提供指导和解决方法。

Check out the articles linked herein to learn more about pip-based virtual environments.查看此处链接的文章,了解有关基于 pip 的虚拟环境的更多信息。

I hope this is helpful to the original poster and gives pip and conda aficionados some things to think about.我希望这对原始海报有所帮助,并为 pip 和 conda 爱好者提供一些思考的东西。

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

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