pip3 没有安装目标模块版本

pip3 does not install the target module version

在 Ubuntu Studio 18.04 上使用 Python 3.6.9 和 pip 9.0.1,我试图将 PyQt5 模块从版本 5.10.1 降级到 5.9.2。

安装似乎没有问题完成,但是pip3确认5.10.1安装成功:

pip3 install --no-cache-dir 'PyQt5==5.9.2'

输出:

Collecting PyQt5==5.9.2
  Downloading https://files.pythonhosted.org/packages/3a/c6/26270f5550f00920045c2f0b222a7d03d7a64382825c68bf0bb1a51d854c/PyQt5-5.9.2-5.9.3-cp35.cp36.cp37-abi3-manylinux1_x86_64.whl (105.3MB)
    100% |████████████████████████████████| 105.3MB 11.0MB/s 
Collecting sip<4.20,>=4.19.4 (from PyQt5==5.9.2)
  Downloading https://files.pythonhosted.org/packages/8a/ea/d317ce5696dda4df7c156cd60447cda22833b38106c98250eae1451f03ec/sip-4.19.8-cp36-cp36m-manylinux1_x86_64.whl (66kB)
    100% |████████████████████████████████| 71kB 4.2MB/s 
Installing collected packages: sip, PyQt5
Successfully installed PyQt5-5.10.1 sip-4.19.8

检查当前版本:

pip3 show PyQt5

输出:

Name: PyQt5
Version: 5.10.1
Summary: Python bindings for the Qt cross platform UI and application toolkit
Home-page: https://www.riverbankcomputing.com/software/pyqt/
Author: Riverbank Computing Limited
Author-email: info@riverbankcomputing.com
License: GPL v3
Location: /home/stragu/.local/lib/python3.6/site-packages
Requires: sip

我也尝试过卸载并再次安装它,但我最终安装了 5.10 版(即 而不是 5.10.1)。好像它强制将 5.10 版本作为最低版本。

但是,当我在 Python3 内核中执行以下操作时:

from PyQt5.Qt import PYQT_VERSION_STR
print("PyQt version:", PYQT_VERSION_STR)

我发现它显然使用的是 5.9.2 版本!

知道这里会发生什么吗?

您正在使用系统的 Python。该模块也随 Apt 在系统范围内安装。 Pip 行为的异常是由于 Debian 补丁。


我(盲目地)猜到第一个 checking PyQt5 packages in Bionic 显示版本号 5.10.1 你看到的。

检查 the source archive for pip 9.0.1-2.3~ubuntu1.18.04.1 (available from https://launchpad.net/ubuntu/+source/python-pip/9.0.1-2.3~ubuntu1.18.04.1) 中的补丁显示 set_user_default.patch 中的以下相关更改:

When running as a normal user in a non-virtual environment, default to --user and --ignore-installed.

(与 相比,我猜这是为了修复 pip install 的用户体验。)

但是,补丁仅将此应用于 install 命令。

所以你安装 PyQt5-5.9.2 到用户站点——而 pip3 show 显示你在系统站点的包,你需要 运行 pip3 list --user 才能看到后者.

我不知道为什么 pip3 install 最后显示了一个错误的版本,但我猜该行是由支持 pip3 show.

的相同代码生成的

看来此安装的默认 pip3 版本 9.0.1 有问题,它总是报告(在安装结束时,或使用 pip3 list 列出模块版本时)该模块有史以来安装的最高版本。

我升级了 pip3:

python3 -m pip install --upgrade pip

它现在按预期工作,报告用户要求的正确模块版本号(与从 Python3 内核中查找相关模块版本号时检索到的任何内容相匹配)。