Rul*_*lle 7 python pip requirements.txt python-poetry
我有一个 Python3 Poetry 项目,其中有一个pyproject.toml
指定依赖项的文件:
[tool.poetry.dependencies]
python = "^3.10"
nltk = "^3.7"
numpy = "^1.23.4"
scipy = "^1.9.3"
scikit-learn = "^1.1.3"
joblib = "^1.2.0"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
Run Code Online (Sandbox Code Playgroud)
我requirements.txt
使用命令将这些依赖项导出到文件中poetry export --without-hashes -f requirements.txt --output requirements.txt
,生成以下文件requirements.txt
:
click==8.1.3 ; python_version >= "3.10" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and platform_system == "Windows"
joblib==1.2.0 ; python_version >= "3.10" and python_version < "4.0"
nltk==3.8.1 ; python_version >= "3.10" and python_version < "4.0"
numpy==1.24.1 ; python_version >= "3.10" and python_version < "4.0"
regex==2022.10.31 ; python_version >= "3.10" and python_version < "4.0"
scikit-learn==1.2.1 ; python_version >= "3.10" and python_version < "4.0"
scipy==1.9.3 ; python_version >= "3.10" and python_version < "4.0"
threadpoolctl==3.1.0 ; python_version >= "3.10" and python_version < "4.0"
tqdm==4.64.1 ; python_version >= "3.10" and python_version < "4.0"
Run Code Online (Sandbox Code Playgroud)
我在构建 Docker 镜像时用它来安装依赖项。
我的问题:调用时如何省略colorama
上述要求列表中的依赖项poetry export --without-hashes -f requirements.txt --output requirements.txt
?
可能的解决方案:colorama
我可以通过使用 生成requirements.txt
文件来过滤掉该行poetry export --without-hashes -f requirements.txt | grep -v colorama > requirements.txt
。但这似乎很棘手,并且如果 Colorama 要求在该文件中的多行中表达,则可能会破坏事情。有没有更好、更少黑客的方法?
背景:在使用构建 Docker 映像的同时安装此要求列表时,pip install -r requirements.txt
我收到消息
Ignoring colorama: markers 'python_version >= "3.10" and python_version < "4.0" and platform_system == "Windows"' don't match your environment
Run Code Online (Sandbox Code Playgroud)
一位同事认为该消息看起来很难看,并且希望它不可见(但我个人不在乎)。调用poetry show --tree
表明 Colorama 依赖项是 Windows 所必需的,pytest
并且用于使终端颜色在 Windows 上工作。在 Linux 上安装时省略库作为要求在这种情况下不太可能出现问题。