Python 3.10.10环境下无法安装Torch的问题求助
问题重现
D:>pip install torch
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement torch (from versions: none)
ERROR: No matching distribution found for torchD:>pip3 install torch torchvision torchaudio
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement torch (from versions: none)
ERROR: No matching distribution found for torch
解决步骤
更新pip到最新版本
旧版pip可能无法识别PyTorch的兼容包索引,执行以下命令更新:python -m pip install --upgrade pip --user指定兼容的PyTorch版本与安装源
Python 3.10.10支持PyTorch 2.0及以上版本,直接指定版本和官方包源安装:- 若使用CUDA 11.7:
pip install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2+cu117 --index-url https://download.pytorch.org/whl/cu117 - 若仅使用CPU:
pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cpu
- 若使用CUDA 11.7:
解决site-packages不可写问题
若有管理员权限,右键以管理员身份打开命令提示符,再执行安装命令,即可绕过用户安装模式,直接安装到系统site-packages目录。验证版本匹配
执行python --version确认当前Python版本为3.10.x,避免因版本不匹配导致的包查找失败。
内容的提问来源于stack exchange,提问作者Mich

