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
pip批量安装Python库 requirement.txt 离线环境无互联网环境下pip安装Python库
pip批量安装Python库 requirement.txt 离线环境无互联网环境下pip安装Python库
240 3
|
5月前
|
Linux Shell Python
centos执行pip3 install etcd3报错
centos执行pip3 install etcd3报错
|
5月前
|
缓存 Python
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-npf9报错
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-npf9报错
|
6月前
|
Linux Python Windows
【Azure 环境】Windows中安装Python azure-eventhub-checkpointstoreblob-aio模块时出错 ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory:
【Azure 环境】Windows中安装Python azure-eventhub-checkpointstoreblob-aio模块时出错 ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory:
|
7月前
|
开发者 Python
确保你的Python环境中已经安装了`python-docx`模块。如果还没有安装,可以通过pip来安装:
确保你的Python环境中已经安装了`python-docx`模块。如果还没有安装,可以通过pip来安装:
|
7月前
|
开发者 Python
【Python】已解决:(Python3中pip无法安装urllib报错问题) ERROR: Could not find a version that satisfies the requireme
【Python】已解决:(Python3中pip无法安装urllib报错问题) ERROR: Could not find a version that satisfies the requireme
478 0
【Python】已解决:(Python3中pip无法安装urllib报错问题) ERROR: Could not find a version that satisfies the requireme
|
6月前
|
Ubuntu Python
ubuntu build install python3.12 and config pip
该脚本用于在 Ubuntu 上编译安装 Python 3.12,并配置 pip 使用国内镜像源。主要步骤包括安装依赖、下载并解压 Python 源码、编译安装、创建符号链接、配置 pip 源,以及验证安装和更新 pip。通过运行此脚本,可以快速完成 Python 3.12 的安装和配置。
196 0
|
7月前
|
IDE 开发工具 Python
【Python】已解决:pip安装第三方模块(库)与PyCharm中不同步的问题(PyCharm添加本地python解释器)
【Python】已解决:pip安装第三方模块(库)与PyCharm中不同步的问题(PyCharm添加本地python解释器)
1418 0
|
7月前
|
安全 网络安全 Python
【Python】已解决:(pip安装库报错)ERROR: Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访
【Python】已解决:(pip安装库报错)ERROR: Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访
439 0
|
2月前
|
人工智能 数据可视化 数据挖掘
探索Python编程:从基础到高级
在这篇文章中,我们将一起深入探索Python编程的世界。无论你是初学者还是有经验的程序员,都可以从中获得新的知识和技能。我们将从Python的基础语法开始,然后逐步过渡到更复杂的主题,如面向对象编程、异常处理和模块使用。最后,我们将通过一些实际的代码示例,来展示如何应用这些知识解决实际问题。让我们一起开启Python编程的旅程吧!

热门文章

最新文章

推荐镜像

更多