当前位置: 首页 > 后端技术 > Python

安装和卸载pytorch

时间:2023-03-26 18:37:18 Python

安装pytorch方法1运行如下命令将清华镜像添加到Anaconda仓库condaconfig--addchannelshttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/condaconfig--addchannelshttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/condaconfig--setshow_channel_urls是condaconfig--addchannelshttps://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/进入pytorch官网,选择你需要的OS、Package、Language和CUDA,得到下载命令。pytorch官网给出的下载命令是(使用conda下载):condainstallpytorchtorchvisiontorchaudiocudatoolkit=9.2-cpytorch其实发现添加镜像源后,安装pytorch还是需要很长时间,因为"-c火炬”。-cpytorch指定conda获取pytorch的通道,指定为conda自带的pytorch仓库,下载会比较慢。因此,只需去掉-cpytorch,即可使用清华镜像源快速安装pytorch。pipinstalltorch==1.7.0+cu92torchvision==0.8.1+cu92torchaudio==0.7.0-fhttps://download.pytorch.org/whl/torch_stable.html同理如果使用pip下载,去掉pip命令中的“-fhttps://download.pytorch.org/...”安装pytorch方法二(推荐)在https://download.pytorch.org/whl/cu90/torch_stable中找到对应的版本.html,下载它;然后到下载whl文件的位置,使用pipinstallxxx.whl进行安装。安装torchvision注意:torchvision需要安装0.2.1系列,否则会报错!!!pytorch0.4.1和torchvision0.2.1对应命令:pipinstalltorchvision==0.2.1查看当前pytorch版本importtorchprint(torch.__version__)Uninstallpytorch#使用conda卸载Pytorchcondauninstallpytorchcondauninstalllibtorch#使用pip来卸载Pytorchpip卸载火炬