Ubuntu(CentOS、Rockylinux等)快速进入深度学习pytorch环境

这里写自定义目录标题

安装进入系统(如Ubuntu22.04)

docker 、 wsl 、 双系统 、服务器系统

推荐 Ubuntu 20.04:WSL 官方推荐使用 Ubuntu 20.04 或更高版本

安装anaconda

默认安装最新版anaconda

bash 复制代码
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

如果需要指定版本

bash 复制代码
# 进入官网查看需要的系统及其下的版本
https://repo.anaconda.com/miniconda/
# 拼接路径下载
wget https://repo.anaconda.com/miniconda/<FILENAME>

pip、conda换源

pip换源

一步到位:

bash 复制代码
mkdir -p ~/.pip && echo -e "[global]\nindex-url = https://mirrors.aliyun.com/pypi/simple/\n[install]\ntrusted-host=mirrors.aliyun.com" > ~/.pip/pip.conf

或者

bash 复制代码
# 查看pip.conf路径
pip -v config list

# 修改配置文件
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

其他源

bash 复制代码
# 阿里云
http://mirrors.aliyun.com/pypi/simple/
# 豆瓣
http://pypi.douban.com/simple/
# 清华大学
https://pypi.tuna.tsinghua.edu.cn/simple/
# 中国科学技术大学
http://pypi.mirrors.ustc.edu.cn/simple

conda换源

一步到位

bash 复制代码
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

或者

bash 复制代码
# 查看.condarc路径
conda info

# 修改配置文件
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
show_channel_urls: true
ssl_verify: false

其他源

bash 复制代码
# 阿里
channels:
  - http://mirrors.aliyun.com/anaconda/pkgs/main
  - http://mirrors.aliyun.com/anaconda/pkgs/r
  - http://mirrors.aliyun.com/anaconda/pkgs/msys2
show_channel_urls: true
ssl_verify: false

# 中科大
channels:
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
  - https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
  - https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
  - https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
show_channel_urls: true
ssl_verify: false

安装nvidia

WSL 无需手动安装驱动,宿主机的 NVIDIA 驱动会自动共享给 WSL,只需安装 CUDA

bash 复制代码
# 添加图形驱动源
sudo add-apt-repository ppa:graphics-drivers/ppa

# 更新
sudo apt update && sudo apt upgrade

# 查找可安装的版本
ubuntu-drivers devices

# 选择自己需要的版本
sudo apt install nvidia-driver-xxx
# 举个例子
sudo apt install nvidia-driver-550

# 重启
sudo reboot

# 查看已安装的驱动
nvidia-smi

安装pytorch环境

bash 复制代码
conda create -n yourname python=3.8 -y
# 12.6
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
# 11.8
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

针对于wsl的优化

bash 复制代码
# 1. 开启cpu虚拟化
# 进BIOS

# 2. 启用或关闭 Windows 功能",勾选 "Hyper-V""Windows 虚拟机监控程序平台""适用于 Linux 的 Windows 子系统""虚拟机平台"。

# 3. 管理员身份运行
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux,VirtualMachinePlatform

# 4. 重启

# 5. 确认功能开启
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

# 6. wsl 更新
wsl --update

# 7. 安装发行版本
wsl --list --online
wsl --install -d Ubuntu-20.04
相关推荐
字节逆旅10 小时前
ubuntu应用深度守护
ubuntu
Narrastory2 天前
明日香 - Pytorch 快速入门保姆级教程(一)
人工智能·pytorch·深度学习
Narrastory2 天前
明日香 - Pytorch 快速入门保姆级教程(二)
人工智能·pytorch·深度学习
程序员打怪兽3 天前
详解Visual Transformer (ViT)网络模型
深度学习
xy123063 天前
OpenStack Train 部署实战(三)控制节点--keystone服务
centos·openstack
CoovallyAIHub5 天前
仿生学突破:SILD模型如何让无人机在电力线迷宫中发现“隐形威胁”
深度学习·算法·计算机视觉
CoovallyAIHub5 天前
从春晚机器人到零样本革命:YOLO26-Pose姿态估计实战指南
深度学习·算法·计算机视觉
CoovallyAIHub5 天前
Le-DETR:省80%预训练数据,这个实时检测Transformer刷新SOTA|Georgia Tech & 北交大
深度学习·算法·计算机视觉
CoovallyAIHub5 天前
强化学习凭什么比监督学习更聪明?RL的“聪明”并非来自算法,而是因为它学会了“挑食”
深度学习·算法·计算机视觉
CoovallyAIHub5 天前
YOLO-IOD深度解析:打破实时增量目标检测的三重知识冲突
深度学习·算法·计算机视觉