问题:全面的初学者的virtualenv教程?[关闭]

我最近一直在听到有关virtualenv的嗡嗡声,我对此很感兴趣。但是我所听到的只是一点点赞美,而对它的含义或用法却不甚了解。

我正在寻找(理想情况下)后续教程,该教程可以使我从没有Python的Windows或Linux中学习,并解释其每个步骤(无特定顺序):

  • 我应该怎么做才能开始使用 virtualenv
  • 使用virtualenv一个好主意的具体原因
  • 我不能/不能使用的情况 virtualenv
  • 我不应该使用的情况 virtualenv

并逐步(全面)介绍应有可能的几种示例情况。

那么,有什么好的教程可以涵盖这些内容?或者,如果您有时间和兴趣,也许您可​​以在这里回答其中一些问题。在您的答案中,或作为指向答案的教程的链接,这些都是我想知道的。

I’ve been hearing the buzz about virtualenv lately, and I’m interested. But all I’ve heard is a smattering of praise, and don’t have a clear understanding of what it is or how to use it.

I’m looking for (ideally) a follow-along tutorial that can take me from Windows or Linux with no Python on it, and explain every step of (in no particular order):

  • what I should do to be able to start using virtualenv
  • specific reasons why using virtualenv is a good idea
  • situations where I can/can’t use virtualenv
  • situations where I should/shouldn’t use virtualenv

And step through (comprehensively) a couple sample situations of the should+can variety.

So what are some good tutorials to cover this stuff? Or if you have the time and interest, perhaps you can answer a few of those questions here. Either in your answer, or as a link to tutorials that answer it, these are the things I’d like to know.


回答 0


回答 1

Virtualenv是用于创建隔离的 Python环境的工具。

假设您在两个不同的项目A和B中工作。项目A是一个Web项目,团队正在使用以下软件包:

  • Python 2.8.x
  • Django 1.6.x

项目B也是一个Web项目,但是您的团队正在使用:

  • Python 2.7.x
  • Django 1.4.x

您正在使用的机器没有django的任何版本,该怎么办?安装django 1.4?Django 1.6?如果在全局安装django 1.4,很容易将django 1.6指向在项目A中工作?

Virtualenv是您的解决方案!您可以创建2个不同的virtualenv,一个用于项目A,另一个用于项目B。现在,当您需要在项目A中工作时,只需为项目A激活virtualenv,反之亦然。

使用virtualenv时,一个更好的技巧是安装virtualenvwrapper来轻松管理您拥有的所有virtualenv。它是用于创建,工作和删除virtualenv的包装器。

Virtualenv is a tool to create isolated Python environments.

Let’s say you’re working in 2 different projects, A and B. Project A is a web project and the team is using the following packages:

  • Python 2.8.x
  • Django 1.6.x

The project B is also a web project but your team is using:

  • Python 2.7.x
  • Django 1.4.x

The machine that you’re working doesn’t have any version of django, what should you do? Install django 1.4? django 1.6? If you install django 1.4 globally would be easy to point to django 1.6 to work in project A?

Virtualenv is your solution! You can create 2 different virtualenv’s, one for project A and another for project B. Now, when you need to work in project A, just activate the virtualenv for project A, and vice-versa.

A better tip when using virtualenv is to install virtualenvwrapper to manage all the virtualenv’s that you have, easily. It’s a wrapper for creating, working, removing virtualenv’s.


回答 2

这是另一个好方法:http : //www.saltycrane.com/blog/2009/05/notes-using-pip-and-virtualenv-django/

这说明了如何使用pipvirtualenv和pip需求文件;Scobal的两个建议的教程都非常有帮助,但都是以easy_install中心为中心的。

请注意,这些教程都没有解释如何在virtualenv中运行不同版本的Python-为此,请参见以下SO问题:对virtualenv使用不同的Python版本

Here’s another good one: http://www.saltycrane.com/blog/2009/05/notes-using-pip-and-virtualenv-django/

This one shows how to use pip and a pip requirements file with virtualenv; Scobal‘s two suggested tutorials are both very helpful but are both easy_install-centric.

Note that none of these tutorials explain how to run a different version of Python within a virtualenv – for this, see this SO question: Use different Python version with virtualenv


回答 3

为了在干净的Ubuntu安装上设置virtualenv,我发现此zookeeper教程是最好的-您可以忽略有关zookeper本身的部分。该virtualenvwrapper文档提供类似的内容,但它是在告诉你到底该怎么把你有点稀缺的.bashrc文件。

For setting up virtualenv on a clean Ubuntu installation, I found this zookeeper tutorial to be the best – you can ignore the parts about zookeper itself. The virtualenvwrapper documentation offers similar content, but it’s a bit scarce on telling you what exactly to put into your .bashrc file.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。