更新 Python virtualenv? [英] Update a Python virtualenv?

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

问题描述

能够更新使用 virtualenv --system-site-packages/path/to/myvirtenv 生成的虚拟环境会非常方便,同时考虑到在基础中所做的更改蟒蛇.

It would be really convenient to be able to update a virtual environment produced with virtualenv --system-site-packages /path/to/myvirtenv taking into account changes that have been done in the base Python.

例如,如果 IPython 2.4 已安装在 virtualenv 中,而 IPython 3.0 稍后已安装在基础 Python 中,则应从虚拟环境中删除旧的 IPython,并替换为新软件包的副本.

For example, if IPython 2.4 has been installed in the virtualenv and IPython 3.0 has later been installed in the base Python, the old IPython should be removed from the virtual environment and replaced by a copy of the newer package.

我们怎样才能做到这一点?是否已经有执行此操作的命令?如果没有,是否可以在包 virtualenv 中实现它?

How can we do this? Is there already a command to do this? If not, would it be possible to implement it in the package virtualenv?

PS:当您没有管理员权限时,使用 --system-site-packages 选项生成的虚拟环境非常方便,但如果对基础 Python 的任何修改使虚拟环境出错,它似乎不是好方法!

PS: Working with virtual environments produced with the --system-site-packages option is very convenient when you do not have admin privileges but if any modifications to the base Python make the virtual env buggy, it does not seem to be a good method!

PS:此问题与此问题有关virtualenv 未找到更新的模块.

PS: This issue is related to this question virtualenv not finding updated module.

推荐答案

如果 IPython 2.4 已安装在 virtualenv 中,并且 IPython 3.0 稍后已安装在基础 Python 中,则应从虚拟环境中删除旧的 IPython,并替换为较新软件包的副本.

if IPython 2.4 has been installed in the virtualenv and IPython 3.0 has later been installed in the base Python, the old IPython should be removed from the virtual environment and replaced by a copy of the newer package.

您也许可以调整现有的 virtualenv,例如通过创建一个新文件并将文件复制到现有文件中.但是,我发现最好且安全的更新方式如下:

You might be able to tweak an existing virtualenv, e.g. by creating a new and copying files into the existing one. However, I find the best and safe way to update is as follows:

# preserve installed packages
source /path/to/venv/bin/activate
pip freeze > requirements.txt
deactivate
# careful now, this destroys all
rm -rf /path/to/venv

然后创建一个新的virtualenv

Then create a new virtualenv

# apply base changes
virtualenv --system-site-packages /path/to/venv
source /path/to/venv/bin/activate
pip install -r requirements.txt

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

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