Skip to content

conda ​

目录 ​


参考资料:

镜像源 ​

conda 的配置文件在~/.condarc,可以通过修改该文件来配置镜像源

~/.condarc
changeps1: true
auto_activate_base: false
channels:
  # 清华镜像
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - 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
  # 默认源
  - defaults
  - conda-forge

show_channel_urls: true

custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

proxy_servers:
#   http: http://127.0.0.1:6789
#   https: https://127.0.0.1:6789
ssl_verify: false
bash
# 清除索引缓存
conda clean -i
# 查看chanel
conda config --show channels
# 添加chanel
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
# 删除chanel
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

# 删除镜像源,换回默认源
conda config --remove-key channels

其他镜像源

配置中科大镜像源

bash
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
 #设置搜索时显示通道地址
conda config --set show_channel_urls yes

配置上海交通大学镜像源

bash
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/conda-forge/

# 设置搜索时显示通道地址
conda config --set show_channel_urls yes

常用命令 ​

安装 ​

bash
# 查看目前以安装的包
conda list
# 查看包信息
conda search <package_name>
# 安装指定版本的包
conda install <package_name>=<version>
# 卸载包
conda remove <package_name>
# 更新包
conda update <package_name>

# conda缓存清理
conda clean -p          # 删除没有用的包
conda clean -t          # 删除tar包
conda clean -y --all    # 删除所有的安装包及cache

环境 ​

bash
# 查看所有环境
conda env list
conda info -e

# 删除环境
conda env remove -n <env_name>

创建环境

bash
conda create -n <env_name> python=<version>
# 例如
conda create -n python_3.6 python=3.6

环境切换

bash
conda activate <env_name>
## 例如
conda activate python_3.6

# 退出环境
conda deactivate

# 切换环境
activate <env_name>
## 切换到默认环境
activate base

删除环境

bash
conda env remove -n <env_name> --all

导出环境

bash
conda list -e > requirements.txt

# 或者
conda env export > freeze.yml

导入环境

bash
conda install --yes --file requirements.txt

# 或者
conda env create -f freeze.yml

jupyter ​

bash
# 安装 jupyter
conda install jupyter notebook -y

# 启动 jupyter
jupyter notebook

jupyter notebook 命令行狂暴输出 worning ​

在使用的过程中遇到,jupyter notebook 在命令行里快速,大量输出 worning,导致无法获取 url。

后来发现是因为我在 vscode 连接着 jyputer notebook 的时候退出了 jupyter 导致 vscode 一直在请求 jupyter,重新启动 jupyter 后因为 token 不一样,导致 vscode 一直在请求 jupyter 但无法访问,导致大量输出 worning。

解决方法是重新启动 vscode

jupyter notebook 内核切换 ​

jupyter 默认使用 base 的 python 环境,切换环境需要手动选择

Copyright © 2022 田园幻想乡 浙ICP备2021038778号-1