更换Anaconda源
windows下
Anaconda清华源
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/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --set show_channel_urls yes
Anaconda 中科大源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes
可以去目录C:\Users\<你的用户名>下查看生成的配置文件.condarc.
查看信息
conda info
使用Anaconda创建环境
conda create
-
n pytorch_gpu pip python
=
3.6
并进入创建好的环境
conda activate pytorch_gpu
Pytorch安装
PyTorch 的官网提供了简单的安装方法,只需简单的命令即可。
官网: https://pytorch.org/get-started/locally/
方法一:
可以看到,没有CUDA,没事,我从其他博客那找到了命令,
conda install pytorch torchvision cudatoolkit=9.0 -c pytorch
当然根据自己的实际情况选择不同的版本进行安装。
以上是GPU版本,CPU版本为
conda install pytorch
-
cpu torchvision
-
cpu
-
c pytorch
方法二:
通过pip命令安装
pip install http://download.pytorch.org/whl/cu90/torch-0.4.1-cp36-cp36m-win_amd64.whl
pip install torchvision
以上为GPU版本,CPU版本为
pip install https:
/
/
download.pytorch.org
/
whl
/
cpu
/
torch
-
1.0
.
0
-
cp36
-
cp36m
-
win_amd64.whl
pip install torchvision
验证
为了确保PyTorch是否安装成功,我们需要运行简单的样例代码测试,例如打印出随机生成的张量矩阵,以及gpu是否可以使用
import torch
x = torch.rand(5,5)
print(x)
如果ok,pytorch安装成功。
torch.cuda.is_available()
返回True,GPU版Pytorch安装完毕。