在 virtualenv 中升级 python [英] Upgrade python in a virtualenv

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

问题描述

有没有办法升级 virtualenv 中使用的 python 版本(例如,如果出现错误修复版本)?

Is there a way to upgrade the version of python used in a virtualenv (e.g. if a bugfix release comes out)?

我可以 pip freeze --local >requirements.txt,然后删除目录和pip install -r requirements.txt,但这需要大量重新安装大型库,例如numpy,我经常使用.

I could pip freeze --local > requirements.txt, then remove the directory and pip install -r requirements.txt, but this requires a lot of reinstallation of large libraries, for instance, numpy, which I use a lot.

我可以看出这是从例如 2.6 -> 2.7 升级时的优势,但是 2.7.x -> 2.7.y 呢?

I can see this is an advantage when upgrading from, e.g., 2.6 -> 2.7, but what about 2.7.x -> 2.7.y?

推荐答案

你看到 这个?如果我没有误解那个答案,您可以尝试在旧的 virtualenv 之上创建一个新的 virtualenv.您只需要知道哪个 python 将使用您的 virtualenv(您需要查看您的 virtualenv 版本).

Did you see this? If I haven't misunderstand that answer, you may try to create a new virtualenv on top of the old one. You just need to know which python is going to use your virtualenv (you will need to see your virtualenv version).

如果您的 virtualenv 安装了与旧版本相同的 python 版本并且升级您的 virtualenv 包不是一种选择,您可能需要阅读 this 以便安装您想要的 python 版本的 virtualenv.

If your virtualenv is installed with the same python version of the old one and upgrading your virtualenv package is not an option, you may want to read this in order to install a virtualenv with the python version you want.

编辑

我已经测试了这种方法(在旧方法之上创建一个新的 virtualenv 的方法)并且它对我来说效果很好.我认为如果您从 python 2.6 更改为 2.7 或 2.7 到 3.x,您可能会遇到一些问题,但如果您只是在同一版本内升级(根据需要保持在 2.7),您应该没有任何问题,因为所有的包两个 python 版本都保存在相同的文件夹中(2.7.x 和 2.7.y 包在 your_env/lib/python2.7/中).

I've tested this approach (the one that create a new virtualenv on top of the old one) and it worked fine for me. I think you may have some problems if you change from python 2.6 to 2.7 or 2.7 to 3.x but if you just upgrade inside the same version (staying at 2.7 as you want) you shouldn't have any problem, as all the packages are held in the same folders for both python versions (2.7.x and 2.7.y packages are inside your_env/lib/python2.7/).

如果你改变了你的 virtualenv python 版本,你需要为那个版本重新安装你所有的包(或者只是将你需要的包链接到新版本的包文件夹中,即:your_env/lib/python_newversion/site-packages)

If you change your virtualenv python version, you will need to install all your packages again for that version (or just link the packages you need into the new version packages folder, i.e: your_env/lib/python_newversion/site-packages)

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

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