Conda¶
下载安装miniconda¶
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
source ~/.bashrc
You have chosen to not have conda modify your shell scripts at all.
To activate conda's base environment in your current shell session:
eval "$(/root/miniconda3/bin/conda shell.YOUR_SHELL_NAME hook)"
To install conda's shell functions for easier access, first activate, then:
conda init
If you'd prefer that conda's base environment not be activated on startup,
set the auto_activate_base parameter to false:
如果想要一进入tetminal就激活环境,可以conda config --set auto_activate_base false。
快速使用¶
conda create -n torch113 python=3.10 numpy matplotlib pandas requests
conda activate torch
conda install pytorch torchvision pytorch-cuda=11.6 -c pytorch -c nvidia
conda install pytorch==1.13.1 torchvision==0.14.1 pytorch-cuda=11.7 -c pytorch -c nvidia
deactivate
查看信息¶
conda info
conda config --show
conda config --add envs_dirs dir
conda config --remove envs_dirs dir
# 查看源
conda config --show channels
# 移除源
conda config --remove channels CHANNELS
# 添加源
conda config --add channels CHANNELS
# 显示源
conda config --set show_channel_urls yes
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/main/
conda config --set auto_activate_base false
conda config --set proxy_servers.http http://id:pw@address:port
conda config --set proxy_servers.https https://id:pw@address:port
Create¶
conda install python==3.10
# direct
conda create -n torch113 python=3.10 numpy matplotlib pandas requests
# conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.6 -c pytorch -c conda-forge
# clone
conda create -n traget_env_name --clone source_env_name
# from yaml
conda env create -f environment.yaml
Activate¶
conda activate torch
deactivate
Export environment¶
conda env export > environment.yaml
# conda env create -f environment.yaml
Install packages¶
conda install pytorch torchvision pytorch-cuda=11.6 -c pytorch -c nvidia
conda install pytorch==1.13.1 torchvision==0.14.1 pytorch-cuda=11.7 -c pytorch -c nvidia
进阶使用¶
pip安装位置¶
python -m site
export PYTHONUSERBASE=/mnt/cache/chenrenjie/.conda/envs/torch113
配置环境变量¶
the section on managing environments in the official documentation
echo $CONDA_PREFIX
cd $CONDA_PREFIX
mkdir -p etc/conda/activate.d
vim etc/conda/activate.d/env_vars.sh
cd etc/conda/deactivate.d
切换cuda/gcc版本¶
export PATH=/mnt/cache/share/gcc/gcc-7.3.0/bin:$PATH
export LD_LIBRARY_PATH=/mnt/cache/share/gcc/gcc-7.3.0/lib64:/mnt/cache/share/gcc/mpc-0.8.1/lib:$LD_LIBRARY_PATH
export CUDA_HOME=/mnt/cache/share/cuda-11.7
export PATH=/mnt/cache/share/cuda-11.7/bin::$PATH
export LD_LIBRARY_PATH=/mnt/cache/share/cuda-11.7/lib64:$LD_LIBRARY_PATH
非root配置¶
当普通用户利用ssh登录后:
# 1. 执行init 这里前面的文件位置就换成自己的文件位置
/opt/miniconda3/bin/conda init bash
# 2. 执行
source ~/.bashrc
查看python pkg 安装位置¶
python -m site
vim ~/.condarc #进入家目录下的conda配置文件.condarc
#按i键进入编辑模式,在末端另起一行写入以下命令:
envs_dirs:
- /full/path/to/your/new/dir/for/new/environments/
pkgs_dirs:
- /full/path/to/your/new/dir/for/new/packages/
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
conda config --show-sources
# 修改 .condarc 文件
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- defaults
show_channel_urls: true
default_channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
conda-forge: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
ssl_verify: false