懒猫微服排查篇(二):上架应用后,pip 安装报错 HASH 不一致

懒猫 ENV 查看器第二版更新的时候,审核人员和我说遇到了这个错误。说来也奇怪,都用了 docker 了,也会遇到依赖的问题。

6c779ad7537d89eb4bd9e40c0d69b7d8.png

https://appstore.lazycat.cloud/#/shop/detail/xu.deploy.env

ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE
Expected sha256 4ceb…
Got 5519987f…

因为 pip 在校验阶段就失败,后面的 Flask 等依赖都没装上,于是程序启动时报 ModuleNotFoundError: No module named ‘flask’。

最后我还是替换掉了腾讯云。以清华源为主,其他源为辅:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/sh

# 切换到当前目录
cd "$(dirname "$0")"
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
apk update
apk add python3 py3-pip
# 设一条主索引(可选)
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 给同一个键追加多条 extra-index-url
pip config set global.extra-index-url https://mirrors.aliyun.com/pypi/simple/
pip config set global.extra-index-url https://repo.huaweicloud.com/repository/pypi/simple/
pip config set global.extra-index-url https://mirrors.cloud.tencent.com/pypi/simple/
pip install -r ./requirements.txt --break-system-packages
python3 app.py

网上还有几种办法,后面再遇到的时候可以再尝试:

  1. –no-cache-dir
  2. pip cache purge
  3. pip install –trusted-host=pypi.org –trusted-host=files.pythonhosted.org example_package
  4. rm ~/.cache/pip -rf
  5. 关闭机器代理

参考链接:

https://stackoverflow.com/questions/71435874/pip-these-packages-do-not-match-the-hashes-from-the-requirements-file

懒猫微服排查篇(二):上架应用后,pip 安装报错 HASH 不一致

https://xu-hardy.github.io/懒猫微服排查篇(二):上架应用后,pip-安装报错-hash-不一致/

作者

Xu

发布于

2025-07-02

更新于

2025-07-01

许可协议

评论