作为AI算法工程师,我们日常生活中。或多或少都要遇到糟心问题:“各种环境版本不匹配”,然后需要花费大量时间逐一排查,最后还不得不卸载或者重装系统。 今天我们主要汇总如何使用使用ubuntu,CentOS,Mac更新Pytorch和torchvision,以及如何查看当前python版本。本教程只汇集如何使用pip,conda更新以及卸载Pytorch和torchvision,希望本文对大家有所帮助
一、更新Pytorch和torchvision
我们主要讲解如何所以pip,conda更新Pytorch和torchvision,这样你就可以使用ubuntu,CentOS,Mac更新Pytorch和torchvision。
1、使用Pip更新Pytorch和torchvision
# 列举pip当前可以更新的所有安装包
pip list --outdated --format=legacy
# 更新pytorch和torchvision安装包
pip install --upgrade pytorch torchvision
2、使用conda更新Pytorch和torchvision
# 建议将其添加soumith为您的Anaconda(或Miniconda)的源服务器
conda config --add channels soumith
# 更新pytorch和torchvision安装包
conda update pytorch torchvision
3、卸载Pytorch重新安装
pip uninstall torch
二、如何安装指定版本Pytorch
使用conda安装指定版本
官网安装,这里是官网地址 https://pytorch.org/,建议参考这篇博客先进行镜像换源成清华源。
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
使用pip安装指定版本
python3版本
pip3 install https://download.pytorch.org/whl/cu100/torch-1.1.0-cp37-cp37m-linux_x86_64.whl
pip3 install https://download.pytorch.org/whl/cu100/torchvision-0.3.0-cp37-cp37m-linux_x86_64.whl
三、卸载Pytorch
1、使用conda卸载Pytorch
conda uninstall pytorch
conda uninstall libtorch
2、使用pip卸载Pytorch
pip uninstall torch
四、如何查看当前pytorch版本
有时候我们想要知道当前的pytorch版本,我们可以使用如下代码打印出当前的版本:
python
>>>import torch
>>>print(torch.__version__)
五、查看pytorch对应的cuda版本
python
>>>import torch
>>>torch.version.cuda
六、验证GPU是否可用
import torch
import torchvision
print(torch.cuda.is_available())
参考网址: