深度学习记录配置篇————服务器python虚拟环境配置+pycharm远程连接

服务器配置python虚拟环境

下载anconada

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2020.07-Linux-x86_64.sh

安装ancondada

bash Anaconda3-2020.07-Linux-x86_64.sh

bash Anaconda3-2020.07-Linux-x86_64.sh path,path是ancondada安装的位置,命令后根据提示确认继续确定安装位置。

激活系统环境变量

source ~/.bashrc

服务器多用户下如何使用

因为我是在实验室一组服务器上使用,为了保证各个用户的环境不冲突,默认不激活conda,故使用以下方式使用conda

export PATH="/$HOME/anaconda3/bin:$PATH"
export PATH="$PATH:$HOME/anaconda/bin"

创建环境

conda create -n tensorflow python=3.6

tensorflow是想要创建的环境的名称,可以自行决定

激活环境

source activate tensorflow

此时输入python,进入创建好的环境下

查看python的路径

import sys 
sys.executable 

安装tensorflow和torch

pip install tensorflow-gpu
pip install torch
pip install torchvision

如果需要安装各种包的话,可以使用pip install name或者conda install name安装,这个地方有疑问的话可以看我最开始的本地环境配置文章https://blog.csdn.net/yunlong_G/article/details/107163040

退出环境

source deactivate

pycharm远程连接

官网配置教程https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html

打开pycharm设置解释器

在这里插入图片描述
选择ssh选项并根据自己的服务器设置ip,端口号,和登录用户名,完成后进行下一步
在这里插入图片描述
设置密码填写后到达下面,红框部分需要做好本地项目和服务器项目位置做好映射,建议使用文件夹下拉选择。
在这里插入图片描述

如果没有在上一步修改好,可以进入以下界面修改
在这里插入图片描述
自动同步文件
我比较喜欢在保存情况下再上传,在以下界面进行设置。
在这里插入图片描述

测试深度学习环境代码

创建一个test.py

import tensorflow as tf
tf.compat.v1.disable_eager_execution()#保证sess.run()能够正常运行
hello = tf.constant('hello,tensorflow')
sess= tf.compat.v1.Session()#版本2.0的函数
print(sess.run(hello))
a = tf.constant(10)
b = tf.constant(32)
print(sess.run(a+b))
import torch
flag = torch.cuda.is_available()
print(flag)
ngpu= 1
# Decide which device we want to run on
device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")
print(device)
print(torch.cuda.get_device_name(0))
print(torch.rand(3,3).cuda())

如果运行不成功,不要怕可能是因为文件没有上传成功,可以用以下方式上传
在这里插入图片描述
最后希望大家都可以方便的使用服务器运行自己的代码,建议只是用这个方式调试哈,如果真的想用服务器运行的话,建议使用screen方法就可以解放自己的电脑啦。

Guess you like

Origin blog.csdn.net/yunlong_G/article/details/121532581