康达能否取代对virtualenv的需求?

问题:康达能否取代对virtualenv的需求?

我在安装SciPy时遇到了麻烦,最近发现了Conda,特别是在我正在开发的Heroku应用程序上。

使用Conda,您可以创建与virtualenv十分相似的环境。我的问题是:

  1. 如果我使用Conda,它将取代对virtualenv的需求吗?如果没有,如何将两者一起使用?是否在Conda中安装virtualenv或在virtualenv中安装Conda?
  2. 我还需要使用点子吗?如果是这样,我仍然可以在隔离的环境中使用pip安装软件包吗?

I recently discovered Conda after I was having trouble installing SciPy, specifically on a Heroku app that I am developing.

With Conda you create environments, very similar to what virtualenv does. My questions are:

  1. 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?
  2. Do I still need to use pip? If so, will I still be able to install packages with pip in an isolated environment?

回答 0

  1. 康达取代了virtualenv。我认为这更好。它不仅限于Python,还可以用于其他语言。以我的经验,它提供了更加流畅的体验,尤其是对于科学包装。我第一次在Mac上正确安装MayaVi是使用conda

  2. 您仍然可以使用pip。实际上,conda安装pip在每个新环境中。它知道有关pip安装的软件包的信息。

例如:

conda list

列出当前环境中所有已安装的软件包。Conda安装的软件包显示如下:

sphinx_rtd_theme          0.1.7                    py35_0    defaults

并通过安装的pip带有<pip>标记:

wxpython-common           3.0.0.0                   <pip>
  1. 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.

  2. You can still use pip. In fact, conda installs pip in each new environment. It knows about pip-installed packages.

For example:

conda list

lists all installed packages in your current environment. Conda-installed packages show up like this:

sphinx_rtd_theme          0.1.7                    py35_0    defaults

and the ones installed via pip have the <pip> marker:

wxpython-common           3.0.0.0                   <pip>

回答 1

简短的答案是,您只需要conda。

  1. Conda在单个软件包中有效地结合了pip和virtualenv的功能,因此,如果您使用的是conda,则不需要virtualenv。

  2. 您会惊讶conda支持多少个软件包。如果还不够,可以在conda下使用pip。

这是到conda页面的链接,用于比较conda,pip和virtualenv:

https://docs.conda.io/projects/conda/zh-CN/latest/commands.html#conda-vs-pip-vs-virtualenv-commands

Short answer is, you only need conda.

  1. Conda effectively combines the functionality of pip and virtualenv in a single package, so you do not need virtualenv if you are using conda.

  2. You would be surprised how many packages conda supports. If it is not enough, you can use pip under conda.

Here is a link to the conda page comparing conda, pip and virtualenv:

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


回答 2

虚拟环境和 pip

我会补充说,使用Anaconda可以轻松创建删除 conda环境。

> conda create --name <envname> python=<version> <optional dependencies>

> conda remove --name <envname> --all 

激活的环境中,通过conda或安装软件包pip

(envname)> conda install <package>

(envname)> pip install <package>

这些环境与conda的pip式软件包管理紧密相关,因此创建环境以及安装Python和非Python软件包都很简单。


朱皮特

此外,在环境中安装ipykernel在Jupyter笔记本的“内核”下拉菜单中会添加一个新列表,从而将可复制的环境扩展到笔记本。从Anaconda 4.1开始,添加了nbextensions,更轻松地为笔记本添加了扩展名。

可靠性

以我的经验,conda在安装大型库(例如numpy和)时更快,更可靠pandas。此外,如果您希望转移环境的保留状态,则可以通过共享克隆环境来实现。

Virtual Environments and pip

I will add that creating and removing conda environments is simple with Anaconda.

> conda create --name <envname> python=<version> <optional dependencies>

> conda remove --name <envname> --all 

In an activated environment, install packages via conda or 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.


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.

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 sharing or cloning an env.


回答 3

安装Conda将使您能够根据需要创建和删除python环境,从而为您提供与virtualenv相同的功能。

对于这两种发行版,您将能够创建一个隔离的文件系统树,在其中您可以根据需要安装和删除python软件包(可能是pip)。如果您想为不同的用例使用同一个库的不同版本,或者只想尝试进行一些发行并将其删除以节省磁盘空间,则可能会派上用场。

差异:

许可协议。虽然virtualenv已获得MIT最宽松的许可证,但Conda使用3条款BSD许可。

康达为您提供了自己的包装控制系统。这个程序包控制系统通常提供流行的非python软件的预编译版本(对于大多数流行的系统),这可以很容易地使某些机器学习程序包正常工作。也就是说,您不必为系统编译优化的C / C ++代码。虽然这对我们大多数人来说是一个很大的缓解,但它可能会影响此类库的性能。

与virtualenv不同,Conda至少在Linux系统上复制了一些系统库。该库可能不同步,从而导致程序行为不一致。

判决:

Conda很棒,应该是您开始机器学习之路的默认选择。它将为您节省一些时间,使他们无法使用gcc和许多软件包。但是,Conda并没有取代virtualenv。它引入了一些额外的复杂性,而这些复杂性可能并非总是需要的。它具有不同的许可。您可能要避免在分布式环境或HPC硬件上使用conda。

Installing Conda will enable you to create and remove python environments as you wish, therefore providing you with same functionality as virtualenv would.

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.

Differences:

License agreement. While virtualenv comes under most liberal MIT license, Conda uses 3 clause BSD license.

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.

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.

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.


回答 4

我同时使用和(截至2020年1月)它们具有一些肤浅的差异,因此适合我的不同用法。通过默认康达更喜欢在一个中央位置来管理你的环境的列表,而使得的virtualenv在当前目录中的文件夹。前者(集中式)在您进行机器学习时才有意义,例如,您有几个广泛的环境可用于许多项目,并且想从任何地方跳入其中。如果您正在做一些一次性项目,这些项目具有完全不同的lib需求集,而lib需求集实际上更多地属于项目本身,则后者(每个项目文件夹)才有意义。

Conda创建的空环境约为122MB,而virtualenv约为12MB,因此,这是您可能不希望将Conda环境分散在各处的另一个原因。

最后,表明Conda偏爱其集中式env的另一个表面现象是(同样,默认情况下),如果您确实在自己的项目文件夹中创建了一个Conda env并激活它,则出现在外壳中的名称前缀是(太长)绝对值文件夹的路径。您可以通过给它命名来解决该问题,但是virtualenv默认情况下做对了。

我希望随着两个程序包管理者争夺霸主地位,此信息会迅速过时,但这是今天的权衡:)

I use both and (as of Jan, 2020) they have some superficial differences that lend themselves to different usages for me. By default Conda 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.

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.

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.

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 :)


回答 5

Pipenv是另一个新的选择,也是我当前首选的启动和运行环境的方法。

目前,它是Python.org官方推荐的Python打包工具

Another new option and my current preferred method of getting an environment up and running is Pipenv

It is currently the officially recommended Python packaging tool from Python.org


回答 6

是的,conda它比容易安装得多virtualenv,并且几乎可以替代后者。

Yes, conda is a lot easier to install than virtualenv, and pretty much replaces the latter.


回答 7

我在公司工作,在几台没有管理员权限的计算机的防火墙后面

以我有限的python使用经验(两年),我遇到了几个库(JayDeBeApi,sasl),这些库通过pip安装时会抛出C ++依赖项错误错误:需要Microsoft Visual C ++ 14.0。使用“ Microsoft Visual C ++生成工具”获得它:http : //landinghub.visualstudio.com/visual-cpp-build-tools

这些用conda安装得很好,因此从那以后,我开始使用conda env。但是要阻止conda从c.programfiles里面安装依赖项并不容易,因为我没有写权限。

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

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.