如何解决Poetry项目中Albumentations与Sentry-sdk的版本冲突?
问题描述
在Poetry项目中使用albumentations==1.1.0和pandas==1.4.2,集成Sentry时遭遇两处版本冲突:
- Pillow版本冲突:
albumentations依赖scikit-learn,后者要求Pillow>=9.1.1,但sentry-sdk==22.8.0强制依赖Pillow==9.0.1,导致版本解析失败,错误日志如下:
SolverProblemError Because sentry (22.8.0) depends on pillow (9.0.1) and no versions of sentry match >22.8.0,<23.0.0, sentry (>=22.8.0,<23.0.0) requires pillow (9.0.1). So, because tag-predicter depends on both Pillow (^9.1.1) and sentry (^22.8.0), version solving failed.
- pytz版本冲突:
pandas>=1.4.2要求pytz>=2020.1,但sentry-sdk>=22.8.0,<23.0.0依赖pytz==2018.9,引发兼容性冲突,错误日志:
SolverProblemError Because no versions of pandas match >1.4.2,<1.4.3 || >1.4.3,<1.4.4 || >1.4.4,<2.0.0 and pandas (1.4.2) depends on pytz (>=2020.1), pandas (>=1.4.2,<1.4.3 || >1.4.3,<1.4.4 || >1.4.4,<2.0.0) requires pytz (>=2020.1). And because pandas (1.4.4) depends on pytz (>=2020.1) and pandas (1.4.3) depends on pytz (>=2020.1), pandas (>=1.4.2,<2.0.0) requires pytz (>=2020.1). Because no versions of sentry match >22.8.0,<23.0.0 and sentry (22.8.0) depends on pytz (2018.9), sentry (>=22.8.0,<23.0.0) requires pytz (2018.9). Thus, sentry (>=22.8.0,<23.0.0) is incompatible with pandas (>=1.4.2,<2.0.0). So, because tag-predicter depends on both pandas (^1.4.2) and sentry (^22.8.0), version solving failed.
解决方法
方案1:升级sentry-sdk到兼容版本
sentry-sdk 23.0.0及后续版本已放宽Pillow和pytz的依赖限制,不再强制绑定旧版本。修改pyproject.toml中的依赖配置:
sentry-sdk = "^23.0.0"
执行poetry update sentry-sdk,让Poetry重新解析并安装兼容版本。
方案2:调整pandas版本范围(业务允许时)
若项目可兼容更高版本pandas,将版本范围修改为支持与sentry-sdk兼容的pytz版本,或直接升级到pandas 2.x系列(需提前测试业务代码兼容性):
pandas = "^1.4.2 || ^2.0.0"
执行poetry update pandas,检查冲突是否解决。
方案3:使用Poetry依赖覆盖功能(风险自担)
若必须保留现有版本的albumentations、pandas和sentry-sdk,可强制指定冲突依赖的版本,忽略Poetry的版本检查:
在pyproject.toml中添加:
[tool.poetry.overrides] pillow = "^9.1.1" pytz = "^2020.1"
执行poetry install完成安装。注意:此方法可能导致sentry-sdk出现潜在兼容性问题,需全面测试功能。
方案4:降级albumentations或scikit-learn
若业务允许,查找并降级albumentations到不依赖高版本Pillow的版本,或降级scikit-learn到要求Pillow<=9.0.1的版本,匹配sentry-sdk的依赖要求。修改pyproject.toml后执行poetry update即可。
内容的提问来源于stack exchange,提问作者Lightbells
相关产品推荐
相关产品推荐

