全部操作都在pycharm中进行
一,安装cuda
直接去官网下载安装cuda,我安装的是12.1版本的
二,在pycharm终端里面运行一下代码查看返回结果
python -c "import torch; print(torch.__version__)"
python -c "import torchvision; print(torchvision.__version__)"
python -c "import torchaudio; print(torchaudio.__version__)"
一般第一次返回结果三个不会同时是什么什么+cu,因为我已经配好了所以我的是什么什么+cu121
三,先把版本不符的卸载一下,运行下面命令
pip uninstall torch torchvision torchaudio
四,安装符合版本的 torch torchvision torchaudio(我的cuda版本是12.1,如果cuda版本不一样,需要自己查找相关符合版本的,不能直接复制下面代码)
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124