将 virtualenvs 移动到另一个主机文件夹 [英] Move the virtualenvs to another host folder

查看:39
本文介绍了将 virtualenvs 移动到另一个主机文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于错误,我在创建虚拟环境之前忘记指定 WORKON_HOME 变量,它们是在 /root/.virtualenvs 目录中创建的.他们工作得很好,我通过激活某些环境然后执行 (env)$ pip freeze 来查看那里安装了哪些特定模块.

By error, I forgot to specify the WORKON_HOME variable before creating my virtual environments, and they were created in /root/.virtualenvs directory. They worked fine, and I did some testing by activating certain environment and then doing (env)$ pip freeze to see what specific modules are installed there.

所以,当我发现 workon home path 错误时,我需要将主机目录更改为 /usr/local/pythonenv.我创建了它并将/root/.virtualenvs目录的所有内容移动到/usr/local/pythonenv,并更改了WORKON_HOME的值多变的.现在,使用 workon 命令激活环境似乎工作正常(即,提示更改为 (env)$),但是如果我执行 (env)$ pip freeze,我得到了比以前更长的模块列表,并且这些模块不包括在移动之前安装在该特定环境中的模块.

So, whe I discovered the workon home path error, I needed to change the host directory to /usr/local/pythonenv. I created it and moved all the contents of /root/.virtualenvs directory to /usr/local/pythonenv, and changed the value of WORKON_HOME variable. Now, activating an environment using workon command seems to work fine (ie, the promt changes to (env)$), however if I do (env)$ pip freeze, I get way longer list of modules than before and those do not include the ones installed in that particular env before the move.

我想仅仅移动文件并为 WORKON_HOME 变量指定另一个目录是不够的.是否有一些配置,我应该在其中指定主机目录的新位置,或者特定环境的一些配置文件?

I guess that just moving the files and specifying another dir for WORKON_HOME variable was not enough. Is there some config where I should specify the new location of the host directory, or some config files for the particular environment?

推荐答案

Virtualenvs 在默认情况下不可重定位.您可以使用 virtualenv --relocatable <virtualenv> 将现有的 virtualenv 转换为可重定位的 virtualenv,看看是否有效.但该选项是实验性,并不真正推荐使用.

Virtualenvs are not by default relocatable. You can use virtualenv --relocatable <virtualenv> to turn an existing virtualenv into a relocatable one, and see if that works. But that option is experimental and not really recommended for use.

最可靠的方法是创建新的虚拟环境.使用 pip freeze -l >旧的requirements.txt获取已安装包的列表,创建新的virtualenv,并使用pip install -r requirements.txt在新的包中安装包.

The most reliable way is to create new virtualenvs. Use pip freeze -l > requirements.txt in the old ones to get a list of installed packages, create the new virtualenv, and use pip install -r requirements.txt to install the packages in the new one.

这篇关于将 virtualenvs 移动到另一个主机文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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