镜像下载、域名解析、时间同步请点击 阿里云开源镜像站
第一步:配置镜像源,安装必要环境
更换镜像
第二步:安装anaconda
1 进入官网
2 下载linux的sh版


3 在对应位置通过命令输入
sh 文件名.sh
4 选择 YES

5 选择 NO (我们要自定义配置环境)

第三步:安装完成Anconda后配置环境
1 编辑环境变量
vim ~/.bashrc
2 添加内容
export PATH="/自己对应的路径名/anaconda3/bin:$PATH"
3 激活修改的内容
source ~/.bashrc
4 测试
conda
若没有显示not fond 则表示 anaconda安装成功
第四步:通过Anaconda创建pytorch空间,用于pytorch
前提知要:
使用anaconda安装环境后,本地默认环境成为base环境
自己创建的环境通过 conda activate 空间名字(环境名字)进入
退出自己创建的环境到默认环境:conda deactivate
1 创建空间,命名为pytorch
conda create -n pytorch
2 进入pytorch空间
conda activate pytorch

ps,若在执行命令的时候出现一下问题:

执行
source activate

第五步:在base环境中 安装cuda
1 安装 nvidia-cuda-toolkit 工具
sudo apt-get install nvidia-cuda-toolkit
2 检查系统推荐显卡驱动,记录下recommend选项
sudo ubuntu-drivers devices

3 添加驱动源
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
4 在Ubuntu系统中找到 软件和更新 选择 驱动

等待更新完毕后再reboot
reboot
5 重启后的测试
nvidia-smi
记录 cuda 版本

6 下载cuda
官网
https://developer.nvidia.com/cuda-toolkit-archive
我的是11.4

选择11.4的哪个版本都可以,接下去按照如下选择去下载
注意:linux的版本要确保正确

7 安装cuda(执行自己上面红框的内容)
wget https://developer.download.nvidia.com/compute/cuda/11.4.4/local_installers/cuda_11.4.4_470.82.01_linux.runsudo
sh cuda_11.4.4_470.82.01_linux.run



8 环境配置
sudo gedit ~/.bashrc
末尾加入
export PATH="/自己对应的路径名/anaconda3/bin:$PATH"
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/extras/CPUTI/lib64
export CUDA_HOME=/usr/local/cuda/bin
export PATH=$PATH:$LD_LIBRARY_PATH:$CUDA_HOME
9 测试
source ~/.bashrc
nvcc -V
cd ~/NVIDIA_CUDA-11.4_Samples/1_Utilities/bandwidthTest/
make
./bandwidthTest

第六步:在pytorch环境中 安装 pytorch环境
1 进入官网
2 安装
选择pytorch版本
选择好对应的系统
选择使用什么安装,conda里可以使用pip安装的
选择语言:python
选择cuda版本:我的版本是11.4

复制命令
3 通过命令进入pytorch环境
source activate
conda activate pytorch
4 执行自己官网复制的命令
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113

done~撒花 💐
番外
删除conda环境
conda uninstall -n 名称 --all
原文链接:https://blog.csdn.net/qq_33806001/article/details/124850247
网友评论