anaconda基本配置流程

anaconda下载

通过清华源下载anaconda:

https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

选择合适的版本后一路 enter+yes 即可。

.bashrc配置

  • 若一直回车,该文件已被配好,不需要更改。
  • 若未被激活,(base)不显示

    1. 在末尾追加anaconda3的下载路径到资源文件

      1
      2
      echo 'export PATH="/home/user/anaconda3/bin:$PATH"' >> ~/.bashrc
      source ~/.bashrc ##刷新资源,使之生效
    2. 创建.bash_profile,与.bashrc同目录,内容如下,创建好后source ~/.bash_profile

      1
      2
      3
      if[ -f"$HOME/.bashrc"];then
      ."$HOME/.bashrc"
      fi

conda换源 (.condarc配置)

在命令行vim ~/.condarc进入编辑该文件

1
2
3
4
5
6
7
8
9
10
11
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/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- defaults
show_channel_urls: true

proxy_servers:
http: http://xxxx.com.cn:80
https: https://xxxx.com.cn:80

最后的proxy_servers是代理配置

conda使用

  • 新建环境: conda create -n env_name python=3.7

  • 激活环境: conda activate env_name

  • 退出环境:conda deactivate

  • 删除环境:conda remove -n env_name --all

  • 查看环境列表:conda env list

  • 安装包:conda install pkg_name

  • 导出环境:conda env export > env_name.yml

  • 根据yaml新建:conda env create -f env_name.yml

    environment.yml:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    name: tactile_ssl
    channels:
    - pytorch
    - xformers
    - nvidia
    - conda-forge
    dependencies:
    - python=3.9
    - pytorch=2.0.*
    - pytorch-cuda=11.8
    - torchvision
    - lightning=2.0.*
    - xformers
    - hydra-core
    - hydra-colorlog
    - wandb
    - matplotlib
    - einops
    - tqdm
    - scipy
    - scikit-learn
    - opencv
    - h5py
    - rich
    - pip
    - pip:
    - rootutils
    - pre-commit
    - ikpy
    - gdown==5.1.0

pip更换源

在命令行mkdir ~./pip && vim ~./pip/pip.conf进入编辑该文件

1
2
3
4
5
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple # 表示使用清华源

[install]
trusted-host = pypi.tuna.tsinghua.edu.cn # 表示添加信任

注:个人理解的更换源的原因:1.官方源在国外速度慢 2.添加代理之后如果不更换源操作不了

拓展:mamba activate tactile_ssl

本文参考:Python更换pip源方法过程解析-腾讯云开发者社区-腾讯云 (tencent.com)