Windows服务器上配置pytorch
1.进入Linux系统
在这里我使用的是XShell,进行指令操作的。你们可以根据自己电脑系统寻找相关的。
Xshell 使用教程
2.在服务器安装 anaconda
在上一步对 Xshell 配置好以后,进入其对话框里面,输入指令如下:
wget -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2020.11-Linux-x86_64.sh
下载界面如下所示:
下载结束以后,再次输入指令bash Anaconda3-2020.11-Linux-x86_64.sh
接下来就是一路按键 Enter 直到你阅读完用户协议以后。出现如下:
我们就要输入 yes,下图情景,按 Enter
出现下图以后,再次按键 Enter ,得到下图,输入yes
这个地方我们就可以告一段落了。
3.导入环境变量,创建新环境
- 编辑变量
在 XShell 中输入指令vim ~/.bashrc
进入下图样式:
我们要对这个地方进行编辑,按键 i,进入编辑模式。在最后一行添加 export PATH=/home/user_name/anaconda3/bin:$PATH加粗文字user_name文字替换为你的姓名的缩写,比如zhangsan。
输入完毕后按 Esc 退出编辑,然后输入:wq保存退出。
注意:这里的/home 对应的应该是您服务器中根目录的其中一个文件夹
2. 再输入source ~/.bashrc
,XShell应显示如下:
到这里,至此Anaconda安装与环境变量设置成功,conda命令已可用.
3.添加清华源
添加清华镜像的指令,手动输入,一定不要输错!一定不要输错!一定不要输错!
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
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 --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --set show_channel_urls yes
4.创建新的环境,并且安装pytorch
- 创建新的环境
输入下面的指令,在新的环境中,导入torch包。创建环境的指令,在我的另外一个博客中提到过。Windows10 系统中配置安装PyTorch环境
conda create -n XXX python=3.8.5
- 进入新创建的环境中
conda activate XXX
,安装 pytorch 指令如下:
conda install pytorch torchvision torchaudio cudatoolkit=10.1
5.验证是否安装成功
- 先进python环境,指令
python
- 测试是否CUDA可以使用。如下图指令: