在 Debian 系统上安装打印机驱动(例如 hplip
)时,我遇到了一次比较典型的 依赖冲突问题。这里记录一下问题的现象、原因以及解决办法,希望能帮到遇到相同情况的朋友。
问题现象
在 Debian 10 (buster) 上安装 hplip
时,执行:
sudo apt install hplip
报错提示缺少依赖,于是尝试单独安装:
sudo apt install python3-pil python3-reportlab
结果出现错误:
依赖 python3 (< 3.8),但是 3.9.2-3 正要被安装
也就是说,python3-pil
和 python3-reportlab
这两个包要求的 Python 版本必须小于 3.8,而我系统里已经有了 3.9.2,导致依赖直接冲突,安装失败。
原因分析
-
Debian 10 (buster) 默认自带 Python 3.7。
-
我的系统里不知不觉已经装上了 Python 3.9(很可能是从 bullseye 或 backports 源拉下来的)。
-
但 buster 源里的
python3-pil
、python3-reportlab
等包,依赖关系写死了python3 (< 3.8)
。 -
于是:系统里 Python 太新,依赖包太老 → 冲突。
换句话说,就是 系统处于"Debian 10 + 部分 Debian 11 包"的混合状态,APT 的依赖链被破坏了。
解决方案对比
针对这种情况,有三种思路:
方案 1:回退 Python,保持纯 Debian 10
卸载掉 python3.9,重新装回 3.7,然后再装依赖。
缺点是软件版本老,不推荐。
方案 2:升级系统到 Debian 11 ✅(推荐)
既然 Python 已经是 3.9,干脆把整个系统升级到 Debian 11 (bullseye) ,保持一致性。
操作步骤:
-
编辑源列表:
sudo nano /etc/apt/sources.list
将
buster
全部替换为bullseye
:deb http://deb.debian.org/debian bullseye main contrib non-free deb http://deb.debian.org/debian bullseye-updates main contrib non-free deb http://security.debian.org/debian-security bullseye-security main contrib non-free
-
更新并全面升级:
sudo apt update sudo apt full-upgrade
-
安装依赖和 hplip:
sudo apt install python3-pil python3-reportlab hplip
至此,依赖问题完全解决,hplip 可以正常安装。
方案 3:保持 Debian 10,但用 HP 官方安装脚本
HP 官方提供了 hplip.run
脚本,直接绕过 apt 依赖,自带 Python 检测。
适合不想升级系统的用户。
-
去官网下载最新版本:
👉 HP Linux Imaging and Printing (HPLIP)
-
下载
.run
文件,例如:bashwget https://downloads.sourceforge.net/project/hplip/hplip/3.23.12/hplip-3.23.12.run
-
安装:
bashsh hplip-3.23.12.run