PyTorch学习二 —— CentOS 7 安装多环境 Anaconda3-5.3.0 + PyTorch 0.4.1

安装 Anaconda3-5.3.0

1、进入官网获取下载链接

官网:https://www.anaconda.com/download/#linux -> Download 右击复制链接地址
在这里插入图片描述

2、在CentOS 中执行安装

# 下载
wget https://repo.anaconda.com/archive/Anaconda3-5.3.0-Linux-x86_64.sh

# 执行安装
sh Anaconda3-5.3.0-Linux-x86_64.sh

安装过程中会显示配置路径
Prefix=/home/app/anaconda3
在这里插入图片描述
设置环境变量
在这里插入图片描述
验证安装 执行

python

显示以下内容则安装成功
在这里插入图片描述

3、创建 Anaconda 的 PyTorch 环境

此部分来源于:https://blog.csdn.net/thormas1996/article/details/80822268

创建一个新的python3环境,新环境一般会安装在anaconda/bin/envs下,也可以自定义路径

conda create --name PyTorch python=3.7

注:如果报错python3不在channel中,表明bin目录下没有python3文件。
配置需要的python版本前先到anaconda/bin下查看有哪些python的版本,文件名字是什么。
比方说有时候python3会被默认命名为python或者python36,不确定python版本的话,执行 python 命令查看。

执行后如下图:
在这里插入图片描述

激活 PyTorch 环境

source activate PyTorch

# 其它相关命令
# 退出虚拟环境
source deactivate

# 查看已建立的虚拟环境
conda info --envs

# 删除环境
conda remove -n PyTorch --all

# 修改环境名称
conda create --name pytorch-0.4.1 --clone PyTorch

如下图所示:
在这里插入图片描述

安装 PyTorch 0.4.1

1、官网查询下载命令

官网:https://pytorch.org/get-started/locally/

在这里插入图片描述

2、安装 PyTorch

conda install pytorch -c pytorch
pip3 install torchvision

如下图所示:
在这里插入图片描述
在这里插入图片描述

3、验证安装

python

import torch

a = torch.Tensor((3,5))
print(a)

如图所示
在这里插入图片描述

自动化安装脚本

installPyTorch.sh
下载地址:https://download.csdn.net/download/qq_28413435/10752554
注:执行到安装Anaconda时需要在是否将变量写入系统环境变量选项中选择yes,否则需要自行配置环境变量,导致安装失败不能继续进行,默认安装路径:/home/app/anaconda3,如需修改请自行修改Shell文件。

#!/bin/bash

# Download Anaconda3-5.3.0-Linux-x86_64.sh
if [ ! -f "/root/Anaconda3-5.3.0-Linux-x86_64.sh" ];then
    echo "===================== Downloading the Anaconda3-5.3.0-Linux-x86_64.sh ====================="
    wget https://repo.anaconda.com/archive/Anaconda3-5.3.0-Linux-x86_64.sh
fi

# Run Anaconda3-5.3.0-Linux-x86_64.sh
echo "===================== Installing the Anaconda3-5.3.0 ====================="
yum install -y bzip2
sh Anaconda3-5.3.0-Linux-x86_64.sh
if [ $? -ne 0 ];then
    rm -rf /home/app/anaconda3
    exit $?
fi

source ~/.bashrc

# Show Conda Version
conda -V
if [ $? -ne 0 ];then
    exit $?
fi

# Set up Tsinghua mirror image
# echo "===================== Set up Tsinghua mirror image ====================="
# 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 --set show_channel_urls yes

# Create Anaconda Environments
echo "===================== Create Anaconda Environments ====================="
conda create --name PyTorch python=3.7

# Activate the PyTorch Environment
source activate PyTorch

# Show Python Version
python -V

# Installing PyTorch0.4.1
echo "===================== Installing PyTorch0.4.1 ====================="
conda install pytorch -c pytorch
if [ $? -ne 0 ];then
    exit $?
fi
pip install torchvision
if [ $? -ne 0 ];then
    exit $?
fi
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wj11771

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值