CentOS 7下的pytorch安装

CentOS 7下的pytorch安装

A. 安装Anaconda3

官网下载x64版安装包,拷贝到当前目录,直接安装:

./Anaconda3-2019.03-Linux-x86_64.sh

注意看安装完毕后的提示:

You have chosen to not have conda modify your shell scripts at all.
To activate conda's base environment in your current shell session:

eval "$(/home/luy/anaconda3/bin/conda shell.YOUR_SHELL_NAME hook)"

To install conda's shell functions for easier access, first activate, then:

conda init

If you'd prefer that conda's base environment not be activated on startup,
   set the auto_activate_base parameter to false:

conda config --set auto_activate_base false

B. 管理虚拟环境

# 创建/激活/关闭虚拟环境
conda create --name pytorch python=3.6 #
conda activate pytorch
conda deactivate # 退出虚拟环境

# 查看已建立的虚拟环境
conda info --envs

# 删除虚拟环境
conda remove -n pytorch --all

# 修改虚拟环境名称
conda create --name pytorch-0.4.1 --clone pytorch

C. 安装必备类库

# 安装pytorch和torchvision
conda install pytorch -c pytorch
conda install torchvision -c pytorch

# 安装ipython、pyqt5,以便后继x-windows远程调用
conda install ipython
pip install pyqt5
pip list

# 安装其他必要的库
conda install matplotlib pandas seaborn scipy numpy
pip install pygame opencv-python

D. 确认X11-forwarding正常

客户端配置

  • mobaXterm系统配置: 默认配置,确认SSH中X11-forwarding/compression已开启,确认X11 serv已经开启
  • mobaXterm session: 确认配置中X11-forwarding/compression均已开启,登录服务器时,banner中显示各项特性已正常开启

服务器配置

  1. 确认sshd中的X11 forwarding已开启
vim /etc/ssh/sshd_config
  1. 确认DISPLAY环境变量,如无,则检查sshd/ssh X11-forwarding配置
#预期为:localhost:10.0
echo $DISPLAY
  1. 确认已安装x-org-apps,重要!
yum whatprovides */xeyes
yum install xorg-x11-apps -y

#预期:应能在本地客户端看到eyes
xeyes
  1. py v-env下,确认ipython、pyqt5已安装
source activate pytorch
conda install ipython

pip list | grep pyqt
conda list | grep pyqt
pip install pyqt5

E. 验证安装情况

使用mobaXterm,远程登录服务器,然后在ipython中,验证如下情况:

# 验证1:验证matplotlib后端
import matplotlib
print(matplotlib.get_backend())

# 验证2:验证x-windows工作正常,在客户端可以看到plot图表
import matplotlib
import matplotlib.pyplot as plt
plt.plot([1,3,2,5,4,10,3,8,56,6])
plt.show()

# 验证3:验证torch正常,tensor已成功上传至gpu显存
import torch
a = torch.Tensor((3,5))
print(a)

你可能感兴趣的:(pytorch)