安装命令:
conda install pytorch1.7.0 torchvision0.8.0 torchaudio==0.7.0 cudatoolkit=10.1 -c pytorch -y
1.修改/root/.bashrc中的环境配置:
.bashrc文件只做了最后export的添加。
# .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' alias vi='vim' alias wc='watch -n 0.1 nvidia-smi' alias ppy='ps -ef | grep python' if [ -f /etc/bashrc ]; then . /etc/bashrc fi # >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! __conda_setup="$('/root/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "/root/anaconda3/etc/profile.d/conda.sh" ]; then . "/root/anaconda3/etc/profile.d/conda.sh" else export PATH="/root/anaconda3/bin:$PATH" fi fi unset __conda_setup # <<< conda initialize <<< export CUDA_HOME=$CUDA_HOME:/usr/local/cuda export PATH=$PATH:/usr/local/cuda/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64 export TERMINFO=/usr/share/terminfo # 最后这句话是添加的 Export PATH="/root/anaconda3/bin:$PATH"
2.换源:
进入/root/.condarc文件(这个是索引文件)中,修改成下面的源:
channels: - defaults show_channel_urls: true default_channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 custom_channels: conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
3.上述完成后,
3.1 进入自己的虚拟环境conda acitvate myTestEnv
3.2 myTestEnv]# python
3.2 >>> import torch
3.3 >>> torch.cuda.is_available()