pytorch 有中⽂⽹站,可以直接去命令合集。
1.先查看 CUDA 版本:
cat /usr/local/
2.查看 CUDNN 版本:
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
⼆、使⽤conda安装pytorch(⽅式⼀)
执⾏如下命令即可(如果第⼀次报错就多执⾏两次):
conda install pytorch torchvision cudatoolkit=8.0 -c pytorch
如果执⾏多次还是报错,那么考虑下⾯的⽅法......
修改conda镜像源
在终端运⾏以下命令修改镜像源,可以明显加速安装。
#优先使⽤清华conda镜像
conda config --prepend channels mirrors.tuna.tsinghua.edu/anaconda/pkgs/free/ #据说加上下⾯清华⼤学conda的main镜像,可以安装、更新最新版本的软件,没试过~~~
#conda config --add channels mirrors.tuna.tsinghua.edu/anaconda/pkgs/main/ #也可以选⽤科⼤conda镜像
conda config --prepend channels mirrors.ustc.edu/anaconda/pkgs/free/
要查看镜像源是否安装成功的话,建议终端中运⾏以下命令:
conda config --set show_channel_urls yes
会⽣成⼀个~/.condarc⽂件,运⾏cat命令查看⽂件内容
cat ~/.condarc
显⽰内容为
channels:
- mirrors.tuna.tsinghua.edu/anaconda/pkgs/free/
- defaults
show_channel_urls: true
如果要切回默认源,则执⾏
conda config –remove-key channels
安装pytorch
在终端输⼊如下命令,安装pytorch(感觉并没有加快安装速度,也⽤了将近⼀下午时间,只是安装成功率提⾼了):conda install pytorch torchvision cudatoolkit=8.0 -c pytorch
测试
在终端中按以下顺序运⾏命令:
python
在打开的python命令⾏中运⾏如下命令,不报错说明安装成功~~~
import torch
import torchvision
print(torch.__version__)
注:其实到此pytorch就算安装完成了,但pytorch版本过低的话import torch.optim.lr_scheduler as lrs会报错,好像
pytorch0.2以后才有的lr_scheduler⽅法,踩过的坑特意注明⼀下。
三、使⽤pip或pip3安装pytorch 0.3.1和torchvision(⽅式⼆)
除了使⽤conda以外,我们还可以使⽤pip管理⼯具,当我们python2.x时,使⽤pip安装,python3.x时候,可以使⽤pip3安装(但安装了python3.x默认就是python3,⽽且python3可以使⽤pip安装,这个还不太清楚怎么回事⼉~~~):
包管理器服务器CUDA
Python版
本
操作⽅法
pip osx cuda8python2.7pip install torchvision
# macOS Binaries dont support CUDA install from source if CUDA is needed
pip osx cuda9.0python2.7pip install torchvision
# macOS Binaries dont support CUDA
install from source if CUDA is needed
pip osx cuda9.1python2.7pip install torchvision
# macOS Binaries dont support CUDA install from source if CUDA is needed
pip osx cudanone python2.7pip install torchvision
# macOS Binaries dont support CUDA install from source if CUDA is needed
pip osx cuda8python3.5pip3 install torchvision
# macOS Binaries dont support CUDA install from source if CUDA is needed
pip osx cuda9.0python3.5pip3 install torchvision
# macOS Binaries dont support CUDA install from source if CUDA is needed
pip osx cuda9.1python3.5pip3 install torchvision
# macOS Binaries dont support CUDA install from source if CUDA is needed
pip osx cudanone python3.5pip3 install torchvision
# macOS Binaries dont support CUDA install from source if CUDA is needed
pip osx cuda8python3.6pip3 install torchvision
# macOS Binaries dont support CUDA install from source if CUDA is needed
pip osx cuda9.0python3.6pip3 install torchvision
# macOS Binaries dont support CUDA install from source if CUDA is neededubuntu安装教程
pip osx cuda9.1python3.6pip3 install torchvision
# macOS Binaries dont support CUDA install from source if CUDA is needed
pip osx cudanone python3.6pip3 install torchvision
# macOS Binaries dont support CUDA install from source if CUDA is needed
pip linux cudanone python2.7pip install torchvision
# if the above command does not work then you have python 2.7 UCS2
use this command
pip linux cuda8python2.7pip install torchvision
# if the above command does not\ work then you have python 2.7 UCS2
use this command
pip linux cuda9.0python2.7pip install torchvision
# if the above command does not\ work then you have python 2.7 UCS2
use this command
pip install torchvision
# if the above command does not\ work
发布评论