Pytorch入门——安装

Pytorch目前支持的平台有Linux和OSX,在Pytorch官网上每种平台提供了conda、pip、source三种安装方式,同时也可以根据有无GPU进行cuda安装,在这里以ubuntu14.04进行安装学习。

1. Anaconda安装配置 
安装过程参考我之前的Anaconda+Tensorflow+Theano+Keras安装博客。 
由于墙的问题,用conda安装Pytorch过程中会连接失败,这是因为Anaconda.org的服务器在国外。在这里可以用清华TUNA镜像源,包含Anaconda仓库的镜像,将其加入conda的配置,配置如下:

# 添加Anaconda的TUNA镜像
$  conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
# TUNA的help中镜像地址加有引号,需要去掉

# 设置搜索时显示通道地址
$  conda config --set show_channel_urls yes
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

执行完上述命令后,会生成~/.condarc文件,记录着对conda的配置,直接手动创建、编辑该文件是相同的效果。

2. Pytorch安装 
在这里的安装,我采用conda安装: 
这里写图片描述

$  conda install pytorch torchvision -c soumith
  • 1

3. 测试 
进入python模式下,看能否导入torch成功:

$  python
>  import torch

猜你喜欢

转载自blog.csdn.net/u013185349/article/details/78028911