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://.....
阿新 • • 發佈:2021-10-08
背景
- Python 3.9
- pip 21.2.3
- poetry1.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.51Downloading 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