conda总结
初始化
默认使用conda activate
命令时会报错,需要给zsh初始化conda配置:
conda init zsh
这样默认启动zsh时会会激活一个base
虚拟环境,它是把激活命令写到文件.zshrc
了。
环境变量的操作
# 删除
conda remove -n your_env_name --all
# 创建
conda create -n your_env_name python=3.7
# 克隆
conda create -n your_env_name --clone exists_env_name
# 离线克隆
conda create -n your_env_name --clone exists_env_name --offline
# 激活
source activate your_env_name
conda activate your_env_name
# 反激活
conda deactivate
# 查看当前虚拟环境
conda info -e
# 查看所有虚拟环境
conda env list
Channel操作
# 移除清华源
conda config --remove-key channels
环境迁移
导出当前环境
conda env export > env.yaml
env.yaml
内容:
name: dt
channels:
dependencies:
- python=3.6
- pip
- pip:
- jupyter==1.0.0
- deeptables
使用yaml导入虚拟环境
conda env create -f env.yaml
更新环境:
conda env update -f env.yaml
conda 也提供了专门的环境迁移工具 conda-pack
也可以将虚拟环境目录打包带到新机器上用,但是需要确保这个机器的系统版本、软硬件环境大致一样。比如都是intel e5 的cpu,系统都是 centos7.3,系统中安装的软件版本也一样。
查找python包
从anaconda.org 查找python包。有的包在default channel中如果找不到可从这个网站上搜索,比如python-geohash
:
可以看到是在conda-forge
channel中,对应的安装命令:
conda install -c conda-forge python-geohash
Debug 开启debug日志
和pip 一样可以使用-v
参数来显示日志,比如:
conda install -vv numpy
conda-forge中常用的库
conda-forge是社区驱动的库,一般第三方项目都发布到这个库里。
featuretools
python-geohash
lightgbm
pyarrow #
do not install pyarrow from conda, see more python-error-using-pyarrow-arrownotimplementederror-support-for-codec-snappy
修复conda的问题
如果玩坏了,可以重装conda:
conda update --force conda
配置文件
配置文件位置在~/.condarc
:
channels:
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_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/pkgs/pro
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
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
rapidsai: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
对于上面的配置文件如果执行:
conda install -c conda-forge python-geohash
它会正常从https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
里安装。如果执行:
conda install -c nvidia cudatoolkit
它会显示找不到nvidia
这个channel。没有指定的channel 没有在custom_channels
中,它会默认从channel_alias
里找也就是查找https://mirrors.tuna.tsinghua.edu.cn/anaconda/nvidia
,
channel_alias
的默认值是https://conda.anaconda.org
,可以将channel_alias
去掉就会从官方channel中安装了。