重命名 virtualenv 文件夹而不破坏它 [英] Renaming a virtualenv folder without breaking it
问题描述
我已经创建了文件夹并在其中初始化了一个 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/
.
Now I want to rename myproject/
to 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 --可重定位环境
$ 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屋!