Python 常见问题 - pip install 指定 poetry 导出的 requirements.txt,报错 ERROR: In --require-hashes mode, all requirements must have their versions pinned with ==. These do not: cffi>=1.1 from https://.....

简介: Python 常见问题 - pip install 指定 poetry 导出的 requirements.txt,报错 ERROR: In --require-hashes mode, all requirements must have their versions pinned with ==. These do not: cffi>=1.1 from https://.....

背景


  • Python 3.9
  • pip 21.2.3
  • poetry 1.1.8

执行了命令,导出 requirements.txt

poetry export  -f requirements.txt --output requirements.txt    

 

查看 requirements.txt

image.png

每个库都有 hash 加密字段

 

执行 pip install 命令

pip3 install --no-cache-dir --upgrade  -r requirements.txt  

 

就报错了

#8 28.40 Collecting websockets==10.0
#8 28.51   Downloading websockets-10.0-cp39-cp39-manylinux2010_x86_64.whl (107 kB)
#8 29.38 Collecting cffi>=1.1
#8 29.38 ERROR: In --require-hashes mode, all requirements must have their versions pinned with ==. These do not:
#8 29.38     cffi>=1.1 from https://files.pythonhosted.org/packages/be/2a/6d266eea47dbb2d872bbd1b8954a2d167668481ff34ebb70ffdd1113eeab/cffi-1.14.6-cp39-cp39-manylinux1_x86_64.whl#sha256=f3ebe6e73c319340830a9b2825d32eb6d8475c1dac020b4f0aa774ee3b898d1c (from bcrypt==3.2.0->-r /code/requirements.txt (line 19))
------
executor failed running [/bin/sh -c pip install --no-cache-dir --upgrade -r /code/requirements.txt]: exit code: 1


排查思路


  • 卸载 cffi 库重新安装,不行
  • 重新生成 requirements.txt 文件再安装,不行
  • 没则,google 搜下,搜到类似问题的 issue,看来是已知问题,并且 poetry 官方也还没修复好,只提供了规避方法
  • https://github.com/actions/virtual-environments/issues/2245

 

解决方案


poetry export命令中传递此标志 --without-hashes

poetry export --without-hashes -f requirements.txt --output requirements.txt

我使用的是这个办法,实践过的确可以,适用于使用 poetry 的小伙伴

 

后面的这几种场景还没试过

 

场景一

停止使用 pip --contstraints标志传递带有固定散列的包

 

场景二

如果直接使用 pip 则将其固定到 20.3 之前的版本

python -m pip install --upgrade pip==20.2.4

 

场景三

如果正在使用其他 virtualenv 依赖于 pip 的东西,请确保将其版本固定

python -m pip install --upgrade virtualenv==20.0.26

或者使用环境变量 VIRTUALENV_PIP=20.2.4

 

相关文章
|
关系型数据库 MySQL Docker
docker pull mysql:8.0.26提示Error response from daemon: Get “https://registry-1.docker.io/v2/“: EOF错误
docker pull mysql:8.0.26提示Error response from daemon: Get “https://registry-1.docker.io/v2/“: EOF错误
5202 9
|
存储 网络安全
Curl error (60): SSL peer certificate or SSH remote key was not OK for https://update.cs2c.com.cn/NS/V10/V10SP2/os/adv/lic/base/x86_64/repodata/repomd.xml [SSL: no alternative certificate subject name matches target host name 'update.cs2c.com.cn']
【10月更文挑战第30天】在尝试从麒麟软件仓库(ks10-adv-os)下载元数据时,遇到 SSL 证书验证问题。错误提示为:`Curl error (60): SSL peer certificate or SSH remote key was not OK`。可能原因包括证书不被信任、证书与域名不匹配或网络问题。解决方法包括检查网络连接、导入 SSL 证书、禁用 SSL 证书验证(不推荐)、联系仓库管理员、检查系统时间和尝试其他镜像。
5627 1
|
Linux iOS开发 MacOS
python的virtualenv虚拟环境常见问题和命令
`venv`是Python的内置模块,用于创建隔离的虚拟环境。创建虚拟环境如`python3 -m venv myenv`,激活环境在Windows上是`./venv/Scripts/activate`,在Unix-like系统是`source myenv/bin/activate`。退出环境用`deactivate`。`pip list`查看已安装包,`pip install`安装包,`pip freeze > requirements.txt`保存依赖。PyCharm中红色`venv`表示项目使用了虚拟环境。
1939 2
 python的virtualenv虚拟环境常见问题和命令
|
编解码 Linux Python
python常见问题|4-10
python常见问题|4-10
|
Java C++ 开发者
python中常见问题
【7月更文挑战第12天】
593 10
|
Linux 开发工具 git
pip的常用命令和常见问题的解决
当使用pip命令安装Python包时,有时候可以通过使用镜像地址来加速下载速度或解决访问限制的问题。以下是一些常用的pip命令和常见的镜像地址:
3305 3
|
资源调度 编译器 Linux
Windows10系统安装Truffle框架,安装失败,提示:error An unexpected error occurred: “https://xxxxx
Windows10系统安装Truffle框架,安装失败,提示:error An unexpected error occurred: “https://xxxxx
662 0
|
计算机视觉 索引 Python
【Python】已解决:ERROR: Could not find a version that satisfies the requirement cv2 (from versions: none)
【Python】已解决:ERROR: Could not find a version that satisfies the requirement cv2 (from versions: none)
1981 0
|
数据挖掘 开发者 索引
【Python】已解决:ValueError: If using all scalar values, you must pass an index
【Python】已解决:ValueError: If using all scalar values, you must pass an index
3984 0

推荐镜像

更多