重命名virtualenv文件夹而不破坏它 [英] Renaming a virtualenv folder without breaking it

查看:110
本文介绍了重命名virtualenv文件夹而不破坏它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了文件夹并在其中初始化了virtualenv实例.

I've created folder and initialized a virtualenv instance in it.

$ mkdir myproject
$ cd myproject
$ virtualenv env

当我运行(env)$ pip freeze时,它会按原样显示已安装的软件包.

When I run (env)$ pip freeze, it shows the installed packages as it should.

现在我想将myproject/重命名为project/.

$ mv myproject/ project/

但是,现在我跑步

$ . env/bin/activate
(env)$ pip freeze

它表示未安装pip.如何在不破坏环境的情况下重命名项目文件夹?

it says pip is not installed. How do I rename the project folder without breaking the environment?

推荐答案

您需要调整安装以使用相对路径. virtualenv为此提供了--relocatable选项.来自文档:

You need to adjust your install to use relative paths. virtualenv provides for this with the --relocatable option. From the docs:

通常情况下,环境与 具体路径.那意味着你 无法移动环境或 将其复制到另一台计算机.你可以 修复环境以使其适应 可通过以下命令重新定位:

Normally environments are tied to a specific path. That means that you cannot move an environment around or copy it to another computer. You can fix up an environment to make it relocatable with the command:

$ virtualenv-可重定位的ENV

$ virtualenv --relocatable ENV

注意::ENV是虚拟环境的名称,您必须从ENV目录外部运行它.

NOTE: ENV is the name of the virtual environment and you must run this from outside the ENV directory.

这将使一些文件 由setuptools创建或分发 使用相对路径,并且会改变 所有要使用的脚本 activate_this.py,而不是使用 Python解释器的位置 选择环境.

This will make some of the files created by setuptools or distribute use relative paths, and will change all the scripts to use activate_this.py instead of using the location of the Python interpreter to select the environment.

注意:您必须先执行此操作 将任何软件包安装到 环境.如果你做一个 可重定位环境,然后安装 一个新软件包,您必须运行virtualenv -可重新定位.

Note: you must run this after you've installed any packages into the environment. If you make an environment relocatable, then install a new package, you must run virtualenv --relocatable again.

这篇关于重命名virtualenv文件夹而不破坏它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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