python:pythonbrew 和 virtualenv 有什么区别? [英] python: what's the difference between pythonbrew and virtualenv?

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

问题描述

我是 python 新手,我打算学习 django.我对 ruby​​(不是 rails)有一些经验,但我熟悉 RVM我不明白 pythonbrewvirtualenv.我知道 pythonbrewRVM 但我认为 virtualenv 已经在做 RVM 所做的事情(反之亦然,pythonbrew 已经在做 RVM 所做的).有人可以解释一下,也许可以提供一些具体的例子/用法来帮助我理解它.非常感谢!

I am new to python and I am planning to learn django. I had a bit of experience with ruby (not rails) and I am familiar with RVM however I don't understand the difference between pythonbrew and virtualenv. I know pythonbrew is a mimic of RVM but I thought virtualenv is already doing what RVM does (or vice versa that pythonbrew is already doing what RVM does). Can someone please explain and perhaps provide some concrete examples/usages to help me understand it. Thanks very much!

推荐答案

Pythonbrew 类似于 Ruby 的 rvm:它是一个 shell 函数,允许您:

Pythonbrew is akin to Ruby's rvm: It's a shell function that allows you to:

  • 构建一个或多个完整的 Python 独立版本,每个版本都存储在本地在您的主目录下.您可以通过这种方式构建多个版本的 Python.
  • 轻松地在 Python 版本之间切换.

您构建的 Python 彼此完全隔离,并且与系统范围内安装的任何 Python 版本无关.

The Pythons you build are completely isolated from each other, and from whatever version(s) of Python are installed system-wide.

Virtualenv 类似,但又不完全相同.它创建了一个 Python 虚拟环境,从概念上讲,它位于一些现有的 Python 安装之上(通常是系统范围的安装,但并非总是如此).默认情况下,在 Unix 平台(和 Mac)上,它会创建指向各种 Python 库模块的符号链接,因此您实际上是在与真正的"底层 Python 实现共享这些模块.但是,virtualenv 有自己的bin"目录和site-packages"目录.您在 Python 虚拟环境中安装的任何额外内容仅在该环境中可用.

Virtualenv is similar, but not quite the same. It creates a Python virtual environment that, conceptually, sits on top of some existing Python installation (usually the system-wide one, but not always). By default, on Unix platforms (and the Mac), it creates symbolic links to the various Python library modules, so you're literally sharing those modules with the "real" underlying Python implementation. But, virtualenv has its own "bin" directory and "site-packages" directory. Anything extra you install in the Python virtual environment is only available within that environment.

Pythonbrew 的一个优势是它创建的 Python 环境是真正且完全独立的.它们不会被任何在底层基础 Python 安装中搞砸的东西所污染,因为没有基础基础安装.这不适用于 virtualenv 环境.如果你创建了一个 virtualenv Python,然后你以某种方式搞砸了它上面的基础 Python 实例(例如,在以 root 登录时不小心删除了基础 Python 的site"目录的一部分),你会搞砸任何基于 virtualenv 的环境也在那个 Python 上.

One advantage to Pythonbrew is that the Python environments it creates are truly, and completely, self-contained. They cannot be contaminated by anything that gets screwed up in an underlying base Python install, because there isn't an underlying base install. This is not true of virtualenv environments. If you create a virtualenv Python, and then you somehow screw up the base Python instance it sits above (e.g., accidentally deleting part of the base Python's "site" directory while logged in as root), you'll screw up any virtualenv environment based on that Python, too.

不过,virtualenv 有其自身的优势.可能最大的优点是它是轻量级的.由于 Pythonbrew 从头开始​​编译 Python,要创建其环境之一,创建 Pythonbrew Python 环境需要一些时间.相比之下,创建 virtualenv Python 环境真的很快.

However, virtualenv has its own advantages. Probably the biggest advantage is that it is lightweight. Since Pythonbrew compiles Python from scratch, to create one of its environments, creating a Pythonbrew Python environment takes some time. By comparison, creating a virtualenv Python environment is really fast.

事实上,您可以将它们一起使用.以下是您可能想要这样做的一种情况.

You can, in fact, use them together. Here's one situation where you might want to do that.

  • 您的基本系统使用 Python 2.6.
  • 您需要安装 Python 2.7.
  • 无论出于何种原因,您都不能(或不想)在系统范围内安装 Python 2.7,与 Python 2.6 并行.

在这种情况下,您可以使用 Pythonbrew 在您的主目录下安装一个基本的 Python 2.7,它不会与其他地方安装的任何内容发生冲突.然后,您可以创建一个或多个基于 Pythonbrew 安装的 2.7 Python 的轻量级 virtualenv Python 环境.例如,您可以使用 virtualenv 以这种方式为 Python 2.7 启动短期测试环境.

In such a case, you could use Pythonbrew to install a base Python 2.7 under your home directory, where it doesn't conflict with anything installed elsewhere. Then, you can create one or more lightweight virtualenv Python environments that are based on your Pythonbrew-installed 2.7 Python. For instance, you could use virtualenv to spin up short-lived test environments for Python 2.7 that way.

我怀疑大多数人真的会这样做.(我没有.)但你没有理由不能.

I doubt most people actually do that. (I don't.) But there's no reason you can't.

这篇关于python:pythonbrew 和 virtualenv 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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