当接触的东西越多越需要进行分类管理,同样的python环境也需要进行分类管理。anaconda不仅在数据科学有较高的建树,在python环境管理上也同样出色。
这个直接在官网[1]下砸即可,安装过程中需要注意:“Do you wish the installer to prepend the Anaconda install location to PATH in your /home//.bash_profile ?”(“你希望安装器添加Anaconda安装路径在/home/<user>/.bash_profile
文件中吗?”),选择yes即可添加环境变量。
然后需要source一下使环境变量生效
source ~/.bash_profile
conda create -n your_env python=3.7
source activate your_env
# 在jupyter显示该虚环境
conda install ipykernel
conda install nb_conda
# 使用pip安装
pip install your_package
# 使用pip安装通过国内镜像
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple your_package
# 使用conda安装
conda install your_package
# 存在复杂包依赖关系的包使用conda-forge通道安装,例如geopandas
conda install -c conda-forge geopandas
source deactivate your_env
conda env remove --name your_env
一般我们添加环境变量的方法是编辑**.bash_profile或.bashrc**,在文件里插入下面这段代码
export PATH="~/anaconda/bin:$PATH"
但如果你下载了 iTerm2切安装了 zsh 和 oh-my-zsh,这个时候你应该修改 zsh 的配置文件,在文件里加上上面的环境变量,如果还不行,可以在里面加入一行
source ~/.bash_profile
vi ~/.condarc
并将以下内容复制进去,详见清华大学开源软件镜像站[2]
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
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
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/
恢复只需要将.condarc文件删除即可
conda config --set auto_activate_base false
conda自动启动 base 环境
conda config --set auto_activate_base true
[1]
官网: https://www.anaconda.com/download
[2]
清华大学开源软件镜像站: https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/