【问题标题】:Add an entry to requirements.txt that has hash values in it向 requirements.txt 添加一个条目,其中包含哈希值
【发布时间】:2022-02-12 05:48:47
【问题描述】:

我习惯于看到 requirements.txt 具有可选的库以及关联的 [最低] 版本。

pandas==1.0.4

在我现在正在处理的现有项目中,我们有这样的库条目:

argcomplete==1.12.3 \
    --hash=sha256:291f0beca7fd49ce285d2f10e4c1c77e9460cf823eef2de54df0c0fec88b0d81 \
    --hash=sha256:2c7dbffd8c045ea534921e63b0be6fe65e88599990d8dc408ac8c542b72a5445
asgiref==3.4.1; python_version >= "3.6" \
    --hash=sha256:ffc141aa908e6f175673e7b1b3b7af4fdb0ecb738fc5c8b88f69f055c2415214 \
    --hash=sha256:4ef1ab46b484e3c706329cedeff284a5d40824200638503f5768edb6de7d58e9
certifi==2021.5.30; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.6" \
    --hash=sha256:50b1e4f8446b06f41be7dd6338db18e0990601dce795c2b1686458aa7e8fa7d8 \
    --hash=sha256:2bbf76fd432960138b3ef6dda3dde0544f27cbf8546c458e60baf371917ba9ee
cffi==1.14.6; python_version >= "3.6" \
    --hash=sha256:22b9c3c320171c108e903d61a3723b51e37aaa8c81255b5e7ce102775bd01e2c \
    --hash=sha256:f0c5d1acbfca6ebdd6b1e3eded8d261affb6ddcf2186205518f1428b8569bb99 \
    --hash=sha256:99f27fefe34c37ba9875f224a8f36e31d744d8083e00f520f133cab79ad5e819 \
    --hash=sha256:55af55e32ae468e9946f741a5d51f9896da6b9bf0bbdd326843fec05c730eb20 \

该项目确实使用了poetry - 这可能是文件的生成器?它是如何生成这个文件的,我如何添加我的新依赖项——pytest 7.0.0

【问题讨论】:

  • poetry export -f requirements.txt --output requirements.txt python-poetry.org/docs/cli/#options-11 -- 也可以使用 pip 我认为也可以使用其他工具
  • @sinoroc。我想添加新的要求 - 我如何在这个文件中使用所有这些哈希码来做到这一点?
  • 取决于您可以使用的工具以及您的工作流程。使用 pip,首先是 python -m pip install 'pandas==1.0.4',然后是 python -m pip freeze。对于诗歌,首先是poetry add 'pandas==1.0.4',然后是poetry export
  • @sinoroc poetry add 是关键 - 你能回答吗?

标签: python-poetry requirements.txt


【解决方案1】:

首先使用 Poetry CLI 的 add command 添加库:

poetry add 'pandas==1.0.4'

或您可能想要的除==1.0.4 之外的任何其他version constraints

然后生成带有export command的需求文件:

poetry export --format requirements.txt --output requirements.txt

【讨论】:

    猜你喜欢
    • 2015-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-19
    相关资源
    最近更新 更多