使用Poetry安装kornia时无法找到nvidia-cudnn-cu11安装候选包
解决Poetry 1.1.13安装kornia时找不到nvidia-cudnn-cu11的问题
环境信息
- Python 3.8.5(固定版本)
- Poetry 1.1.13(无法升级至v1.2)
问题概述
执行poetry add kornia时出现以下错误:
RuntimeError Unable to find installation candidates for nvidia-cudnn-cu11 (8.5.0.96)
报错位置在~.poetry\lib\poetry\installation\chooser.py第72行。已通过poetry run pip install nvidia-pyindex && poetry run pip install kornia成功用pip安装,但Poetry执行相同流程仍报错;尝试清理缓存、重建虚拟环境、添加源等操作均无效,且因Poetry版本限制无法使用poetry source add命令。
解决方案
方案1:手动配置Poetry全局源(适配1.1.x版本)
Poetry 1.1.x不支持poetry source add命令,但可通过修改全局配置文件添加NVIDIA PyPI源:
- 找到Poetry配置文件路径:
- Windows:
%APPDATA%\pypoetry\config.toml - macOS/Linux:
~/.config/pypoetry/config.toml
- Windows:
- 打开配置文件,添加以下内容:
[[repositories]] name = "nvidia" url = "https://pypi.nvidia.com" - 保存后执行:
poetry cache clear pypi --all poetry env remove python3.8 poetry install poetry add kornia
方案2:手动指定依赖包URL绕过源限制
若方案1仍报错,可直接在pyproject.toml中指定nvidia-cudnn-cu11的下载地址:
- 编辑
pyproject.toml,在[tool.poetry.dependencies]区块添加:nvidia-cudnn-cu11 = { url = "https://pypi.nvidia.com/nvidia-cudnn-cu11/nvidia_cudnn_cu11-8.5.0.96-py3-none-any.whl" } kornia = "*" - 执行以下命令完成安装:
poetry cache clear --all poetry env remove python3.8 poetry install
方案3:基于已安装的pip依赖生成Poetry配置
若已通过poetry run pip install kornia成功安装,可将现有依赖导入Poetry:
- 激活虚拟环境:
poetry shell - 导出当前pip依赖:
pip freeze > requirements.txt - 将依赖批量添加到Poetry:
poetry add $(cat requirements.txt) - 生成新的lock文件:
poetry lock --no-update
说明
nvidia-cudnn-cu11等NVIDIA专属包不在PyPI默认源,Poetry 1.1.x无法自动识别第三方源,需手动配置或指定URL。- 操作前务必清理Poetry缓存并重建虚拟环境,避免旧缓存干扰。
内容的提问来源于stack exchange,提问作者critor
相关产品推荐
相关产品推荐

