pytorch_geometric环境配置一 — pytorch安装

本部分介绍pytorch环境的配置,包括CPU版本和GPU版本。

环境:win10+anaconda+python3.7

1.前置要求

安装完成anaconda后,在anaconda中创建一个虚拟环境以便管理。如:

conda create -n pytorch_learn python=3.7

2.Pytorch安装

pytorch传送门:PyTorch

如果熟悉自己的环境配置,请在官网主页直接选择自己的版本然后在anaconda prompt中输入命令进行安装。(注意要将自己需要配置的虚拟环境进行激活)

值得注意的是,笔者选用这种方式安装失败,主要在于这种方式是通过自带的pytorch仓库进行安装,可能会引发超时和各种玄学问题。

因此,建议各位看官如果是按照我的环境进行配置的话,请通过以下方式进行安装。

2.1 CPU版本

首先添加清华镜像源提高速度。  主要是前三行和最后一行  其余行可自行考虑是否添加

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
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/pytorch/
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/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/peterjc123/
conda config --set show_channel_urls yes

添加完成后,可运行以下代码进行安装。

conda install pytorch torchvision torchaudio cudatoolkit=11.0

2.2 GPU版本

在按照pytorch_geometric环境配置一完成cuda的安装后(参考:深度学习GPU环境CUDA详细安装过程(简单快速有效) - 知乎 (zhihu.com)),按照上述操作添加清华镜像源后,仅将最后的安装代码换为下一行即可。

# CUDA 11.0
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

2.3 环境测试

在编辑器如Pycharm或Jupyter notebook中运行如下代码:

import torch

print(torch.__version__)
print('gpu:', torch.cuda.is_available())

结果如下:

1.7.1+cu110
gpu: True

上面是版本号,下面是书否安装cuda版本,如果是即为True  反之则为False

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值