如何复制virtualenv [英] How to duplicate virtualenv

查看:274
本文介绍了如何复制virtualenv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现成的virtualenv,其中包含很多软件包,但是旧版本的Django。

I have an existing virtualenv with a lot of packages but an old version of Django.

我想做的是重复环境,所以我有另一个环境,它们的软件包完全相同,但 是Django的较新版本。我该怎么做?

What I want to do is duplicate this environment so I have another environment with the exact same packages but a newer version of Django. How can I do this?

推荐答案

最简单的方法是使用pip生成需求文件。需求文件基本上是一个文件,其中包含要安装(或在pip生成文件的情况下已经安装)所有python软件包的列表,以及它们的版本。

The easiest way is to use pip to generate a requirements file. A requirements file is basically a file that contains a list of all the python packages you want to install (or have already installed in case of file generated by pip), and what versions they're at.

要生成需求文件,请进入原始的virtualenv,然后运行:

To generate a requirements file, go into your original virtualenv, and run:

pip freeze > requirements.txt

这将为您生成 requirements.txt 文件。如果在您喜欢的文本编辑器中打开该文件,则会看到类似以下内容的文件:

This will generate the requirements.txt file for you. If you open that file up in your favorite text editor, you'll see something like:

Django==1.3
Fabric==1.0.1
etc...

现在,编辑该行,说 Django == xx Django == 1.3 (或要在新的virtualenv中安装的任何版本) 。

Now, edit the line that says Django==x.x to say Django==1.3 (or whatever version you want to install in your new virtualenv).

最后,激活您的虚拟环境,然后运行:

Lastly, activate your new virtualenv, and run:

pip install -r requirements.txt

pip将自动下载并安装您指定的任何版本的 requirements.txt 文件中列出的所有python模块!

And pip will automatically download and install all the python modules listed in your requirements.txt file, at whatever versions you specified!

这篇关于如何复制virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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