本文开始
为什么需要环境管理?
答:开发环境离不开环境管理简化
,本文介绍以 anyenv
同一管理各种 *env 版本工具,使用 MacOS
透过国内清华 TUNA 镜象
加速,涵盖 homebrew、pyenv、conda、nodenv, jupyter lab 安装。
更新时间:2019/08/10
如何更新 homebrew 镜象?
homebrew 使用清华 TUNA 镜象
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
brew update
homebrew 还原
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
brew update
如何安装 anyenv ?
anyenv 是 *env 集成,支持多种 env 管理工具
安装 anyenv
brew install anyenv
anyenv 支援的环境
anyenv install -l
Renv
crenv
denv
erlenv
exenv
goenv
hsenv
jenv
luaenv
nodenv
phpenv
plenv
pyenv
rbenv
sbtenv
scalaenv
swiftenv
tfenv
anyenv 安装 pyenv
anyenv install pyenv
anyenv install --update
pyenv 如何安装 python 与 conda ?
用 pyenv 安装 miniconda3-latest,miniconda3 是极简包,包含 conda 与 python3。
pyenv build script 从国外下载较慢,由于把对应的 miniconda3-latest build script 的改为清华 TUNA 镜象
sed -i '' "s/repo.continuum.io/mirrors.tuna.tsinghua.edu.cn\/anaconda/g" ~/.anyenv/envs/pyenv/plugins/python-build/share/python-build/miniconda3-latest
pyenv install miniconda3-latest
conda 使用国内镜象
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 show_channel_urls yes
conda 第三方国内镜象
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
如何安装 jupyterlab ?
安装 jupyterlab
conda install jupyterlab
开启 jupyterlab
jupyter lab
如何安装 nodenv/nodejs ?
jupyter lab 会使用到 nodejs,这里以版本 12.7.0 为例,使用国内清华镜象
anyenv install nodenv
sed -i '' s/nodejs.org\/dist/mirrors.tuna.tsinghua.edu.cn\/nodejs-release/g" ~/.anyenv/envs/nodenv/plugins/node-build/share/node-build/12.7.0
nodenv install 12.7.0
如何以 conda 建立特定版本 python 虚拟环境?
conda install --name py362 python=3.6.2
# 从 base 环境切环到 python 3.6.2 环境
conda activate py362
如何以 conda 在虚拟环境下安装特定版本 jupyterlab ?
conda install -n py362 jupyterlab
如何 移除 conda 虚拟环境?
conda env remove -n py363
安装后,如何清除 conda 压缩包?
conda clean -all
如何在 pyenv 移除 miniconda3 环境?
pyenv uninstall miniconda3-latest
如何移除 pyenv ?
anyenv uninstall pyenv
如何移除 nodenv ?
anyenv uninstall nodenv