Ubuntu部署Anaconda虚拟环境

1.安装Nvidia Driver

设置(Settings)->  软件更新(Software Updates)->  附加驱动(Additional Drivers)

Check the Driver命令行下运行:
nvidia-smi



2、安装CUDA Toolkit


sudo apt install nvidia-cuda-toolkit -y

当出现:
You can undo this by running `conda init --reverse $SHELL`? [yes|no]

[no] >>> 

输入yes,则安装程序会自动修改你的 shell 配置文件(比如 .bashrc、.zshrc 或 .bash_profile),将 Conda 的路径添加到你的系统环境变量中。这样做之后,你每次打开新的终端窗口时,都无需手动激活 Conda,可以直接使用 conda 命令,比如 conda create、conda install 等

3)、验证安装 conda --version 出现版本号,则表示安装成功!

4、命令行安装wget和git

sudo apt install wget -y
sudo apt install git -y

5、修改conda的镜像源

「添加清华源」:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2

conda update --all -y

============************==============

为了提升安装速度,可以安装mamba取代conda:

conda install mamba -n base -c conda-forge

mamba create -n myenv python=3.11
mamba activate myenv

============*************==============

6、创建并激活虚拟环境

conda create -n xxx python=3.10 -y && conda activate xxx

7、在虚拟环境中安装pytorch

方案A:
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia -y

方案B:
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121 -i https://pypi.tuna.tsinghua.edu.cn/simple

编写名为test.py的python代码,测试CUDA是否安装正常:

import os
os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'
import torch
if torch.cuda.is_available():
print("CUDA is 正常!")
else:
print("CUDA is 不可用.")

评论

此博客中的热门博文

通过命令行在Github上发布项目的新版本

利用GitHub免费的静态页面托管空间发布网页

本地部署OpenAvatarChat实时交互数字人系统