Python Conda 是否取代了对 virtualenv 的需求?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34398676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does Conda replace the need for virtualenv?
提问by Johan
I recently discovered Condaafter I was having trouble installing SciPy, specifically on a Heroku app that I am developing.
我最近在安装 SciPy 时遇到问题后发现了Conda,特别是在我正在开发的 Heroku 应用程序上。
With Conda you create environments, very similar to what virtualenvdoes. My questions are:
使用 Conda 可以创建环境,这与virtualenv所做的非常相似。我的问题是:
- If I use Conda will it replace the need for virtualenv? If not, how do I use the two together? Do I install virtualenv in Conda, or Conda in virtualenv?
- Do I still need to use pip? If so, will I still be able to install packages with pip in an isolated environment?
- 如果我使用 Conda,它会取代对 virtualenv 的需求吗?如果没有,我如何将两者一起使用?我是在 Conda 中安装 virtualenv,还是在 virtualenv 中安装 Conda?
- 我还需要使用 pip 吗?如果是这样,我还能在隔离环境中使用 pip 安装软件包吗?
采纳答案by Mike Müller
Conda replaces virtualenv. In my opinion it is better. It is not limited to Python but can be used for other languages too. In my experience it provides a much smoother experience, especially for scientific packages. The first time I got MayaVi properly installed on Mac was with
conda
.You can still use
pip
. In fact,conda
installspip
in each new environment. It knows about pip-installed packages.
Conda 替换了 virtualenv。在我看来它更好。它不仅限于 Python,也可用于其他语言。根据我的经验,它提供了更流畅的体验,尤其是对于科学包。我第一次在 Mac 上正确安装 MayaVi 是使用
conda
.您仍然可以使用
pip
. 事实上,conda
安装pip
在每个新环境中。它知道 pip 安装的软件包。
For example:
例如:
conda list
lists all installed packages in your current environment. Conda-installed packages show up like this:
列出当前环境中所有已安装的软件包。Conda 安装的软件包显示如下:
sphinx_rtd_theme 0.1.7 py35_0 defaults
and the ones installed via pip
have the <pip>
marker:
通过安装的那些pip
有<pip>
标记:
wxpython-common 3.0.0.0 <pip>
回答by Mad Physicist
Short answer is, you only need conda.
简短的回答是,您只需要 conda。
Conda effectively combines the functionality of pip and virtualenv in a single package, so you do not need virtualenv if you are using conda.
You would be surprised how many packages conda supports. If it is not enough, you can use pip under conda.
Conda 在一个包中有效地结合了 pip 和 virtualenv 的功能,因此如果您使用 conda,则不需要 virtualenv。
你会惊讶 conda 支持多少个包。如果还不够,可以在conda下使用pip。
Here is a link to the conda page comparing conda, pip and virtualenv:
这是 conda 页面比较 conda、pip 和 virtualenv 的链接:
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。
回答by pylang
Virtual Environments and pip
虚拟环境和 pip
I will add that creatingand removingconda environments is simple with Anaconda.
我要补充一点,使用 Anaconda创建和删除conda 环境很简单。
> conda create --name <envname> python=<version> <optional dependencies>
> conda remove --name <envname> --all
In an activated environment, install packages via conda
or pip
:
在激活的环境中,通过conda
或安装软件包pip
:
(envname)> conda install <package>
(envname)> pip install <package>
These environments are strongly tied to conda's pip-like package management, so it is simple to create environments and install both Python and non-Python packages.
这些环境与conda 的类似 pip 的包管理密切相关,因此创建环境并安装 Python 和非 Python 包都很简单。
Jupyter
木星
In addition, installing ipykernel
in an environment adds a new listing in the Kernels dropdown menu of Jupyter notebooks, extending reproducible environments to notebooks. As of Anaconda 4.1, nbextensions were added, adding extensions to notebooks more easily.
此外,在环境中安装会ipykernel
在 Jupyter 笔记本的内核下拉菜单中添加一个新列表,将可重现的环境扩展到笔记本。从 Anaconda 4.1 开始,添加了 nbextensions,可以更轻松地向笔记本添加扩展。
Reliability
可靠性
In my experience, conda is faster and more reliable at installing large libraries such as numpy
and pandas
. Moreover, if you wish to transfer your the preserved state of an environment, you can do so by sharingor cloningan env.
根据我的经验,conda 在安装大型库(例如numpy
和pandas
. 此外,如果您希望转移环境的保留状态,您可以通过共享或克隆env 来实现。
回答by Liang Huang
Yes, conda
is a lot easier to install than virtualenv
, and pretty much replaces the latter.
是的,conda
它比 更容易安装virtualenv
,并且几乎取代了后者。
回答by y.selivonchyk
Installing Conda will enable you to create and remove python environments as you wish, therefore providing you with same functionality as virtualenvwould.
安装 Conda 将使您能够根据需要创建和删除 python 环境,因此为您提供与virtualenv相同的功能。
In case of both distributions you would be able to create an isolated filesystem tree, where you can install and remove python packages (probably, with pip) as you wish. Which might come in handy if you want to have different versions of same library for different use cases or you just want to try some distribution and remove it afterwards conserving your disk space.
在这两种发行版的情况下,您都可以创建一个独立的文件系统树,您可以在其中根据需要安装和删除 python 包(可能使用 pip)。如果您想为不同的用例使用不同版本的相同库,或者您只想尝试一些发行版并在之后删除它以节省磁盘空间,这可能会派上用场。
Differences:
区别:
License agreement. While virtualenv comes under most liberal MIT license, Condauses 3 clause BSD license.
许可协议。虽然 virtualenv 遵循最自由的MIT 许可证,但Conda使用 3 条款 BSD 许可证。
Conda provides you with their own package control system. This package control system often provides precompiled versions (for most popular systems) of popular non-python software, which can easy ones way getting some machine learning packages working. Namely you don't have to compile optimized C/C++ code for you system. While it is a great relief for most of us, it might affect performance of such libraries.
Conda 为您提供了自己的包控制系统。这个包控制系统通常提供流行的非 python 软件的预编译版本(对于大多数流行的系统),这可以很容易地让一些机器学习包工作。也就是说,您不必为您的系统编译优化的 C/C++ 代码。虽然这对我们大多数人来说是一种极大的解脱,但它可能会影响此类库的性能。
Unlike virtualenv, Conda duplicating some system libraries at least on Linux system. This libraries can get out of sync leading to inconsistent behavior of your programs.
与 virtualenv 不同,Conda 至少在 Linux 系统上复制了一些系统库。这些库可能会失去同步,从而导致程序的行为不一致。
Verdict:
判决:
Conda is great and should be your default choice while starting your way with machine learning. It will save you some time messing with gcc and numerous packages. Yet, Conda does not replace virtualenv. It introduces some additional complexity which might not always be desired. It comes under different license. You might want to avoid using conda on a distributed environments or on HPC hardware.
Conda 很棒,应该是您开始机器学习之路时的默认选择。它将为您节省一些时间来处理 gcc 和众多软件包。然而,Conda 并没有取代 virtualenv。它引入了一些可能并不总是需要的额外复杂性。它来自不同的许可证。您可能希望避免在分布式环境或 HPC 硬件上使用 conda。
回答by Johan
回答by Pat Niemeyer
I use both and (as of Jan, 2020) they have some superficial differences that lend themselves to different usages for me. By defaultConda prefers to manage a list of environments for you in a central location, whereas virtualenv makes a folder in the current directory. The former (centralized) makes sense if you are e.g. doing machine learning and just have a couple of broad environments that you use across many projects and want to jump into them from anywhere. The latter (per project folder) makes sense if you are doing little one-off projects that have completely different sets of lib requirements that really belong more to the project itself.
我同时使用和(截至 2020 年 1 月)它们有一些表面差异,这对我来说有不同的用途。通过默认康达更喜欢在一个中央位置来管理你的环境的列表,而使得的virtualenv在当前目录中的文件夹。如果您正在进行机器学习,并且只有几个广泛的环境可以在许多项目中使用并且想要从任何地方跳入它们,则前者(集中式)是有意义的。如果您正在执行具有完全不同的库需求集的小型一次性项目,而这些库需求实际上更多地属于项目本身,则后者(每个项目文件夹)是有意义的。
The empty environment that Conda creates is about 122MB whereas the virtualenv's is about 12MB, so that's another reason you may prefer not to scatter Conda environments around everywhere.
Conda 创建的空环境大约为 122MB,而 virtualenv 大约为 12MB,所以这是您可能不想将 Conda 环境分散到任何地方的另一个原因。
Finally, another superficial indication that Conda prefers its centralized envs is that (again, by default) if you do create a Conda env in your own project folder and activate it the name prefix that appears in your shell is the (way too long) absolute path to the folder. You can fix that by giving it a name, but virtualenv does the right thing by default.
最后,Conda 更喜欢其集中式 envs 的另一个表面迹象是(同样,默认情况下)如果您确实在自己的项目文件夹中创建了一个 Conda env 并激活它,则出现在您的 shell 中的名称前缀是(太长)绝对文件夹的路径。你可以通过给它一个名字来解决这个问题,但 virtualenv 默认情况下会做正确的事情。
I expect this info to become stale rapidly as the two package managers vie for dominance, but these are the trade-offs as of today :)
我希望这个信息会随着两个包管理器争夺主导地位而迅速变得陈旧,但这些是今天的权衡:)
回答by rohit arora
I work in corporate, behind several firewall with machine on which I have no admin acces
我在公司工作,在几个防火墙后面,我没有管理员权限的机器
In my limited experience with python (2 years) i have come across few libraries (JayDeBeApi,sasl) which when installing via pip threw C++ dependency errors error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
在我对 python 的有限经验(2 年)中,我遇到了几个库(JayDeBeApi、sasl),当通过 pip 安装时会抛出 C++ 依赖错误错误:需要 Microsoft Visual C++ 14.0。使用“Microsoft Visual C++ 构建工具”获取它:http: //landinghub.visualstudio.com/visual-cpp-build-tools
these installed fine with conda, hence since those days i started working with conda env. however it isnt easy to stop conda from installing dependency inside c.programfiles where i dont have write access.
这些与 conda 一起安装得很好,因此从那时起我开始使用 conda env。但是,要阻止 conda 在我没有写访问权限的 c.programfiles 中安装依赖项并不容易。