如何在Python中重命名virtualenv? [英] How to rename a virtualenv in Python?

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

问题描述

在使用以下方法初始化 virtualenv 时,我拼错了名字:

I misspelled the name of the virtualenv while initializing it using:

$ virtualenv vnev

我实际上打算创建名称为的环境venv
尝试将 vnev 文件夹重命名为 venv 后,我发现这没有多大帮助。激活环境的名称仍然重命名了旧的 vnev

I actually intended to create the environment with the name venv. Having tried to rename the vnev folder to venv, I find that this doesn't provide much help. The name of the activate environment still renames the old vnev.

$ mv vnev venv
$ . venv/bin/activate
(vnev) $ deactivate

我想知道如何

推荐答案

默认情况下,virtualenv不支持环境重命名。仅删除virtualenv目录并使用正确的名称创建一个新目录是更安全的。您可以这样操作:

By default virtualenv does not support the renaming of environments. It is safer to just delete the virtualenv directory and create a new one with the correct name. You can do this by:


  1. 激活您的虚拟环境: source vnev / bin / activate

  2. 创建当前安装的软件包的requirements.txt: pip Frozen> requirements.txt

  3. 删除拼写错误的virtualenv: rm -r vnev /

  4. 使用正确的名称创建一个新的virtualenv: virtualenv venv

  5. 激活新的virtualenv: source venv / bin / activate

  6. 从requirements.txt安装软件包: pip install -r requirements.txt

  1. Activate your virtualenv: source vnev/bin/activate
  2. Create a requirements.txt of currently installed packages: pip freeze > requirements.txt
  3. Delete the misspelled virtualenv: rm -r vnev/
  4. Create a new virtualenv with correct name: virtualenv venv
  5. Activate new virtualenv: source venv/bin/activate
  6. Install packages from requirements.txt: pip install -r requirements.txt

如果无法重新创建,则可以使用第三方工具,例如 virtualenv-mv 可能会有所帮助。

If recreating is not an option there are 3rd party tools like virtualenv-mv that might be helpful.

或者,您可以使用 virtualenvwrapper ,它提供了 cpvirtualenv 命令来复制或重命名virtualenvs。

Alternatively you can use virtualenvwrapper which provides the cpvirtualenv command to copy or rename virtualenvs.

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

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