目录
b) 激活创建的虚拟环境,并将Pytorch 安装到这个环境下面
1.安装anaconda
a) 下载anaconda
由于官网的下载速度十分缓慢,而且还不支持断点续传,经常下载失败。故而,去国内的镜像站点下载,我选择的是Anaconda3-5.2.0
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
b) 更改执行权限
sudo chmod +x Anaconda3-5.2.0-Linux-x86_64.sh
c) sudo 执行并安装。
安装期间会有配置安装路径,环境变量和安装软件等操作,自己酌情安装。此步骤执行完毕后,需要重新生效下环境变量文件。
sudo ./Anaconda3-5.2.0-Linux-x86_64.sh
d) 配置anaconda的镜像源地址
#命令行配置
conda config --add channels - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels -
http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels -
http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes
查看修改成功,输入:
cat ~/.condarc
显示:
修改成功。
e) 为conda赋予安装权限
sudo chown -R 1000:1000 /home/luozichao/anaconda3/
2. 安装PyTorch
a) 创建pytorch虚拟环境
conda create -n pytorch python=3.6
b) 激活创建的虚拟环境,并将Pytorch 安装到这个环境下面
source activate pytorch
激活后会显示:
c) 安装Pytorch
在Pytorch官网,根据自己的机器配置选择对应的安装命令。
我自己选择的如下:
命令行执行:
#如官网示例使用 -c pytorch 后缀则会下载官网的安装包,不使用则从anaconda的源镜像地址下载
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.2
执行命令后,会自动安装必须的组件,直至完毕。
d) 判断PyTorch 安装成功
PyTorch版本查看,安装路径查看:
python 环境下,torch 和 torchvision 命令相同
(pytorch) luozichao@luozichao-G7-7588:~$ python3
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'1.7.1'
>>> torch.__path__
['/home/luozichao/.conda/envs/pytorch/lib/python3.6/site-packages/torch']
>>>
至此,所有安装都全部完成。
说明:
conda 已经安装了cudatoolkit 套件,不需要再另行安装了。