在linux环境中使用virtualenv创建虚拟环境,这样就可以在不同,安装:pip install virtualenv;
创建文件夹用于存放虚拟环境,使用命令:virtualenv 环境名称如gpu_test,此时在当前路径下就创建了名为gpu_test的虚拟python环境,进入gpu_test/bin路径,里面有python执行文件。
执行命令:source activate,激活当前虚拟环境,使用deactivate退出当前环境。
如果是windows系统,则是在创建的虚拟环境目录中进入Scripts,执行activate.bat激活环境,执行deactivate.bat退出当前环境。
添加清华源:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
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 --set show_channel_urls yes # 显示镜像源
安装pytorch:conda install pytorch torchvision torchaudio cpuonly
移除清华源:
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
注意:删除的时候最后要有反斜杠"/",否则报错“CondaKeyError: 'channels': 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/' is not in the 'channels' key of the config file”
Linux 查看NVIDIA版本:nvidia-smi,cuda版本:nvcc -V
安装 pytorch官网命令:
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
使用外部源,去掉-c pytorch:
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c nvidia
参考:
Python使用virtualenv创建虚拟环境的详细步骤_python_脚本之家 (jb51.net)
python学习笔记-Pycharm远程连接服务器的Python虚拟环境(Virtualenv) - 乱石之渐 - 博客园 (cnblogs.com)
(2023)CUDA11.7+Python3.9+Pytorch GPU安装_cuda11.7对应的pytorch-CSDN博客
conda | 设置软件源_conda 腾讯源-CSDN博客
anaconda | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror