问题描述
我已经创建了文件夹并在其中初始化了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:
$ 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文件夹而不破坏它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!