• Python 常见问题


    背景

    • Python 3.9
    • pip 21.2.3
    • poetry 1.1.8

    执行了命令,导出 requirements.txt

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

    查看 requirements.txt

    每个库都有 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

     
  • 相关阅读:
    洛谷P3003 [USACO10DEC]苹果交货Apple Delivery
    洛谷P1576 最小花费
    洛谷P1821 [USACO07FEB]银牛派对Silver Cow Party
    洛谷P1948 [USACO08JAN]电话线Telephone Lines
    洛谷P3371【模板】单源最短路径
    洛谷P2384最短路
    FirstOfAll
    Proxy模式:管理第三方API
    Abstract Server模式,Adapter模式和Bridge模式
    Observer模式
  • 原文地址:https://www.cnblogs.com/poloyy/p/15379431.html
Copyright © 2020-2023  润新知