pip、conda下如何下載、更新和刪除pytorch

今天我們主要彙總如何使用使用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

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge

conda config --set show_channel_urls yes

# 更新pytorch和torchvision安裝包
conda update pytorch torchvision

3、卸載Pytorch重新安裝

pip uninstall torch

二、如何安裝指定版本Pytorch

使用conda安裝指定版本

# 比如我們安裝 v10.0
conda install pytorch=10.0 -c soumith

使用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
發佈了276 篇原創文章 · 獲贊 163 · 訪問量 35萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章