Centos服务器conda环境配置脚本
2020-04-04
3 min read
📃说明
本脚本主要包括以下几个功能:
- 从清华源自动下载anaconda并安装
- 配置pip国内源为阿里源
- 配置conda源为ustc(这一步有疑问,因为conda源经常会不可用,需要经常性测试)
- 自动创建tf14环境 安装cudnn和cuda以及pytorch 自动测试GPU环境是否可用
- 自动创建tf20环境 安装cudnn和cuda以及pytorch 自动测试GPU环境是否可用
💾Code
yum install -y bzip2
# download anaconda and install
echo "download anaconda and install"
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh
sh Anaconda3-5.3.1-Linux-x86_64.sh -u
source ~/.bashrc
# change pip source to aliyun
echo "change pip source to aliyun"
if [ ! -d " ~/.pip/" ];then
mkdir ~/.pip
else
echo "pip existed"
fi
cat>~/.pip/pip.conf<<EOF
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF
# change anaconda source to ustc
echo "change anaconda source to ustc"
cat>~/.condarc<<EOF
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
- https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
- https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
- https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
- https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
- defaults
show_channel_urls: true
EOF
#gpu test file
cat>gpu_test.py<<EOF
import os
import tensorflow as tf
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
if tf.test.gpu_device_name():
print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
print('Your tensorflow-gpu is available')
else:
print('Your tensorflow-gpu is not available')
print("Please install GPU version of TF")
import torch
if torch.cuda.is_available():
print('Default GPU Device: {}'.format(torch.cuda.get_device_name()))
print('Your pytorch-gpu is available')
else:
print('Your pytorch-gpu is not available')
print("Please install GPU version of Pytorch")
EOF
# creat tf14 env
echo "creating tf14 env"
conda create -n tf14 python=3.7 -y
conda activate tf14
conda install tensorflow-gpu==1.14.0 -y
pip install torch torchvision -U
pip install numpy==1.15.4
python gpu_test.py
# creat tf20 env
echo "creating tf20 env"
conda create -n tf20 python=3.7 -y
conda activate tf20
conda install tensorflow-gpu==2.0.0 -y
pip install torch torchvision -U
pip install numpy==1.15.4
python gpu_test.py