Ubuntu命令行配置conda环境
Pytoch的gpu加速需要安装cuda,而cuda的安装过程较为繁琐,因此推荐使用conda安装pytorch-cuda环境。 以下是在Ubuntu系统下配置conda环境的步骤。 同时,在conda管理的虚拟环境内可正常使用pip安装其他包。
- 安装Miniconda
- conda会默认在shell启动时激活base环境,可通过conda config --set auto_activate_base false关闭此功能
- 创建新环境:conda create -n [env_name] python=3.9
- 激活环境:conda activate [env_name](或使用vscode python插件的解释器选择)
- conda换源: - code ~/.condarc参考配置:- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - 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 - https://mirrors.sustech.edu.cn/anaconda/pkgs/main - https://mirrors.sustech.edu.cn/anaconda/pkgs/free - https://mirrors.sustech.edu.cn/anaconda/pkgs/r - https://mirrors.sustech.edu.cn/anaconda/pkgs/pro - https://mirrors.sustech.edu.cn/anaconda/pkgs/msys2 custom_channels: conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud msys2: https://mirrors.sustech.edu.cn/anaconda/cloud bioconda: https://mirrors.sustech.edu.cn/anaconda/cloud menpo: https://mirrors.sustech.edu.cn/anaconda/cloud simpleitk: https://mirrors.sustech.edu.cn/anaconda/cloud nvidia: https://mirrors.sustech.edu.cn/anaconda-extra/cloud auto_activate_base: false remote_read_timeout_secs: 600.0 
- pip换源: python -m pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple --upgrade pippip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
- 安装包:conda install [package]或pip install [package]
- Pytoch-CUDA环境:conda install pytorch torchvision torchaudio pytoch-cuda -c pytorch -c nvidia
- 安装Conda中找不到或存在冲突的包:pip install [package]
- 检查pip冲突:pip check
 This post is licensed under  CC BY 4.0  by the author.