无法通过 `pip install -I` 降级 Python 包的版本

为了临时解决兼容性问题,我尝试将 Python 包 arrow 的版本从 0.17.0 降级到 0.13.2。

在特定服务器上我无法安装,因为以下命令调用安装 0.13.2 但最终安装回 0.17.0。如果删除虚拟环境,并生成一个新的并重新安装 0.13.2,它可以正常工作。

我也在虚拟机上进行了测试,降级工作正常,没有这个症状。

我想知道为什么,任何投入都将受到高度赞赏。

(venv3.7) [user@host freeze]$ pip install -I arrow==0.13.2
Collecting arrow==0.13.2
  Using cached arrow-0.13.2-py2.py3-none-any.whl (37 kB)
Collecting python-dateutil
  Using cached python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Collecting six>=1.5
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Installing collected packages: six, python-dateutil, arrow
Successfully installed arrow-0.17.0 python-dateutil-2.8.1 six-1.15.0
(venv3.7) [user@host freeze]$
stack overflow Unable to downgrade version of Python package by `pip install -I`
原文答案

接受的答案

使用 --force-reinstall 而不是 -I, --ignore-installed

根据文档, -I 可以破坏现有安装:

-I, --ignore-installed 忽略已安装的包,覆盖它们。如果现有包的版本不同或使用不同的包管理器安装,这可能会破坏您的系统!

如果您想安装比您当前安装的版本更旧的版本, --force-reinsall 更适合:

--force-reinstall 重新安装所有软件包,即使它们已经是最新的。

--force-reinstall 的实际演示:

$ pip install arrow==0.17.0
Collecting arrow==0.17.0
<... snip ...>
Successfully installed arrow-0.17.0

$ pip install --force-reinstall arrow==0.13.2
Collecting arrow==0.13.2
<... snip ...>
Attempting uninstall: arrow
Found existing installation: arrow 0.17.0
Uninstalling arrow-0.17.0:
  Successfully uninstalled arrow-0.17.0
Successfully installed arrow-0.13.2 python-dateutil-2.8.1 six-1.15.0

$ pip freeze | grep arrow
arrow==0.13.2

答案:

作者头像

luasoftware.com 的另一个选项

% pip install arrow  
Collecting arrow
  Downloading arrow-1.2.1-py3-none-any.whl (63 kB)
     |████████████████████████████████| 63 kB 110 kB/s            
Installing collected packages: six, python-dateutil, arrow
Successfully installed arrow-1.2.1

% pip install --upgrade arrow==0.13.2
Collecting arrow==0.13.2
  Downloading arrow-0.13.2-py2.py3-none-any.whl (37 kB)
    Installing collected packages: arrow
  Attempting uninstall: arrow
    Found existing installation: arrow 1.2.1
    Uninstalling arrow-1.2.1:
      Successfully uninstalled arrow-1.2.1
Successfully installed arrow-0.13.2
% pip list | grep arrow
arrow             0.13.2