非root用户快速在Ubutun服务器配置pytorch环境

安装环境

感觉实验室的服务器老崩,以后肯定还要安装很多次pytorch,这里写个教程记录一下

miniconda的安装

  1. 创建文件夹:mkdir miniconda(文件夹名)
  2. 下载软件安装包:cd miniconda(转到当前文件夹)
  3. 下载miniconda软件
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh
  1. bash Miniconda3-latest-Linux-x86_64.sh
  • 点击control+C 跳过协议阅读
  • 输入两次 yes
  • 重启终端使用miniconda
  1. 修改conda配置信息:
    vim ~/.condarc
    改成:
auto_activate_base: false
channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
ssl_verify: false

参考清华镜像
6. 用命令nvidia-smi查看显卡型号
在这里插入图片描述

安装pytorch-gpu

  1. 创建环境
conda create -n pytorch python=[你要安装的版本号如:3.7]
  1. 激活环境
conda activate pytorch
  1. 删除环境(如果以后需要)
conda remove -n pytorch --all
  1. 退出环境(如果以后需要)
conda deactivate
  1. 在pytorch环境安装pytorch
conda install pytorch-gpu  matplotlib jupyter notebook -y
  1. 安装好了打开python看看:
    在这里插入图片描述
python
import torch
torch.cuda.is_available()

连接VSCode Jupyter NoteBook

  1. 先用

在这里插入图片描述
这个ssh连接远程服务器
2. 用vs code的文件系统创建.ipynb文件并打开根据提示安装插件
3. 在config文件中可以添加一个ServerAliveInterval 60来使ssh不会自动断开链接
在这里插入图片描述
参考openSSH-config

设置免密登入

  1. 在客户端(自己的电脑,该段操作都是在客户端进行)上生成密钥,如果有就跳过
cd ~/.ssh
ssh-keygen -t rsa
  1. 读取并复制公钥匙
cat id_rsa.pub
  1. 客户端使用指令向服务端进行密钥发送
ssh-copy-id [你的用户名]@[xx.xx.xx.xx服务器主机名]
# 如 ssh-copy-id root@192.168.1.1

实现跳板

比如现在我们想在逻辑上先连A,用A再连B
那么:
A是中间跳板服务器
B是最终目的服务器
要在vscode实现,只需在ssh的config文件中,B的最下行加上:

ProxyCommand ssh -W %h:%p [中间跳板服务器的Host]

如下图
在这里插入图片描述

用Git同步

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在Ubuntu上配置Anaconda的PyTorch环境,可以按照以下步骤进行操作: 1. 首先,打开终端并输入以下命令,以激活Anaconda环境配置文件: ``` source ~/anaconda3/etc/profile.d/conda.sh ``` 这样可以确保使用Anaconda的命令和环境。 2. 接下来,创建一个新的虚拟环境。可以使用以下命令创建一个名为"pytorch"的虚拟环境: ``` conda create -n pytorch ``` 按照提示操作,完成虚拟环境的创建。 3. 安装PyTorch。可以使用以下命令安装PyTorch及其相关的软件包: ``` conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=11.0 -c pytorch ``` 这将安装PyTorch 1.7.1、torchvision 0.8.2 和 torchaudio 0.7.2,同时需要指定使用的CUDA版本为11.0。通过 `-c pytorch` 参数,指定了从PyTorch的Anaconda镜像源进行安装。 4. 如果你想加快PyTorch的安装速度,可以更换Anaconda的镜像源。可以编辑Anaconda的配置文件,通过以下步骤更换为清华大学镜像源: - 打开终端,输入以下命令打开配置文件: ``` nano ~/.condarc ``` - 在编辑器中,找到 "channels" 部分,并删除其中的 "defaults" 镜像源。然后,将以下三个镜像源添加到配置文件中: ``` channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ show_channel_urls: true ``` - 保存并关闭文件。 5. 现在,重新运行PyTorch的conda安装命令,你应该能够感受到安装速度的明显提升: ``` conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=11.0 -c pytorch ``` 通过按照上述步骤进行操作,你就可以在Ubuntu上使用Anaconda配置PyTorch环境了。记得根据自己的需求和系统环境进行相应的调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [linux下使用anaconda配置pytorch环境](https://blog.csdn.net/Pythonistas29xs/article/details/126554676)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [ubuntu服务器安装anaconda并配置pytorch环境](https://blog.csdn.net/qq_44218195/article/details/122381668)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值