首页 > 解决方案 > 在 setup.py 中使用 CUDA 安装 PyTorch

问题描述

我正在尝试在 install_requires 中使用 CUDA 指定 PyTorch。使用 pip 安装的命令是

pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio===0.8.0 -f https://download.pytorch.org/whl/torch_stable.html

我如何在 setup.py install_requires 中做到这一点?

标签: pythonpytorchsetup.pyinstall-requires

解决方案


后来我也遇到了同样的问题,我修复了它,但是在setup.py文件中使用它并且它有效,只需将这些行添加到您的setup.py文件中即可。

"torch@https://download.pytorch.org/whl/cu111/torch-1.8.0%2Bcu111-cp37-cp37m-linux_x86_64.whl",
"torchvision@https://download.pytorch.org/whl/cu111/torchvision-0.9.0%2Bcu111-cp37-cp37m-linux_x86_64.wh",
"torchaudio@https://download.pytorch.org/whl/torchaudio-0.8.0-cp36-cp36m-linux_x86_64.whl"

如果您想要任何 MACOSX 或 Windows,所有这些都适用于 linux 版本,只需在每一行中更改 @ 之后的链接,您就可以从中获取所需版本的链接 https://download.pytorch.org/whl/torch_stable.html


推荐阅读