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

 

相关文章
|
4天前
|
Python Windows
Python分发包安装pip3
Python分发包安装pip3
9 0
|
4天前
|
iOS开发 MacOS Python
Python 虚拟环境及pip环境管理
`venv`是Python的虚拟环境管理工具,提供独立的环境避免包冲突,便于管理与删除。创建虚拟环境使用`python3 -m venv test`,激活环境在Windows上运行`. Scripts\activate`,macOS上运行`. bin\activate`。安装Python包通过`python`或`python3`选择版本,使用`pip`进行安装、升级和卸载。`pip`是Python包管理器,自2.7.9和3.4版本起自带,常用命令包括查看版本、安装、升级和卸载包。为提高速度,可使用国内镜像源如阿里云、清华或豆瓣。
12 2
|
4天前
|
JSON 数据格式 开发者
pip和requests在Python编程中各自扮演着不同的角色
【5月更文挑战第9天】`pip`是Python的包管理器,用于安装、升级和管理PyPI上的包;`requests`是一个HTTP库,简化了HTTP通信,支持各种HTTP请求类型及数据交互。两者在Python环境中分别负责包管理和网络请求。
32 5
|
4天前
|
Linux Python Windows
Python更换国内pip源详细教程
Python更换国内pip源详细教程
|
4天前
|
存储 Scala 索引
【零碎知识】pip install 与 conda install 的区别
【零碎知识】pip install 与 conda install 的区别
34 0
|
4天前
|
Python
【Python笔记】pip intall -e命令:让你的工程直接使用开源包的源码,可断点调试,修改源码!
【Python笔记】pip intall -e命令:让你的工程直接使用开源包的源码,可断点调试,修改源码!
20 0
|
4天前
|
机器学习/深度学习 缓存 程序员
Python包管理工具 pip 及其常用命令和参数用法
Python包管理工具 pip 及其常用命令和参数用法
71 0
|
4天前
|
Serverless Linux Windows
在函数计算中,如果pip安装速度较慢
在函数计算中,如果pip安装速度较慢
42 1
|
6月前
|
Linux Python
python2 安装 pip (Linux)
python2 安装 pip (Linux)
60 0
|
6月前
|
Linux Python
linux 安装 pip2 kali debian python python2
linux 安装 pip2 kali debian python python2
71 0