tensorflow/pytorch/指定GPU训练的几种方式 1、python代码中添加: os.environ["CUDA_VISIBLE_DEVICES"] = "0" or # CUDA_VISIBLE_DEVICES=1 2、 命令窗口临时限制环境变量 export CUDA_VISIBLE_DEVICES=1 or CUDA_VISIBLE_DEVICES=2 python xxx.py 要想应用到所有用户,需要在~/.bashrc中最后一行添加此命令。