在Poetry虚拟环境中安装Pytorch+cuda121时出错:来源(pytorch):访问https://download.pytorch.org/时授权错误

问题描述 投票:0回答:1

我希望在我的项目中使用yolov5模型和opencv。我目前正在使用 Poetry 作为我的项目的虚拟环境。

为了使用 GPU 而不是 CPU 来操作 yolov5,我希望安装 cuda。我正在尝试从 https://pytorch.org/ 下载 Cuda 12.1 版本。为此,我按如下方式配置了 pyproject.toml:

[tool.poetry]
name = "yolo-test"
version = "0.1.0"
description = ""
authors = [""]
readme = "README.md"
packages = [{include = "yolo_test"}]

[tool.poetry.dependencies]
python = ">=3.11,<3.13"
opencv-python = "^4.8.0.74"
pyinstaller = "^6.1.0"
pillow = "^10.1.0"
pandas = "^2.1.1"
requests = "^2.31.0"
ultralytics = "^8.0.201"
logging = "^0.4.9.6"

# Cuda installation test
[[tool.poetry.source]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cu121"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

之后,我尝试使用以下命令将其安装在诗歌虚拟环境中:

poetry add torch torchvision torchaudio --source pytorch

但是,在安装过程中,我观察到以下错误日志:

Source (pytorch): Authorization error accessing https://download.pytorch.org/whl/cu121/pefile/
Source (pytorch): Authorization error accessing https://download.pytorch.org/whl/cu121/macholib/
Source (pytorch): Authorization error accessing https://download.pytorch.org/whl/cu121/logging/
Source (pytorch): Authorization error accessing https://download.pytorch.org/whl/cu121/ultralytics/
...

此外,我使用

print(torch.__version__)
进行验证,作为输出,我观察到
2.1.0+cpu
。 谁能帮助我如何在 Poetry 中安装 Pytorch Cuda 版本?

谢谢你。

python deep-learning pytorch yolo python-poetry
1个回答
0
投票

问题是您的 PyTorch 源用于 TOML 文件中列出的所有依赖项。

正确的方法是仅使用 PyTorch 源作为 PyTorch 和 TorchVision 依赖项。您可以通过使用

explicit
源优先级来实现此目的:

[tool.poetry]
name = "yolo-test"
version = "0.1.0"
description = ""
authors = [""]
readme = "README.md"
packages = [{include = "yolo_test"}]

[tool.poetry.dependencies]
python = ">=3.11,<3.13"
torch = { version = "^2.1.0", source = "pytorch" }
opencv-python = "^4.8.0.74"
pyinstaller = "^6.1.0"
pillow = "^10.1.0"
pandas = "^2.1.1"
requests = "^2.31.0"
ultralytics = "^8.0.201"
logging = "^0.4.9.6"

[[tool.poetry.source]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cu121"
priority = "explicit"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

使用此设置,只有

torch
依赖项才会使用
pytorch
源。

© www.soinside.com 2019 - 2024. All rights reserved.