问题描述
是否有办法升级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.您只需要知道哪个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软件包,则您可能需要阅读,以便安装具有所需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版本,则需要再次安装该版本的所有软件包(或仅将所需的软件包链接到新版本的packages文件夹中,即: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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!