首先声明,你可以选择使用 Homebrew 来安装pyenv。我这里主要是想和我 Linux 设备上一致,所以选择使用脚本来安装pyenv。
准备安装脚本
这个安装的脚本来源于官方的的github仓库。
关于安装脚本的解读请看《pyenv 安装脚本解读》。
pyenv-installer.sh
#!/usr/bin/env bash
set -e
[ -n "$PYENV_DEBUG" ] && set -x
if [ -z "$PYENV_ROOT" ]; then
if [ -z "$HOME" ]; then
printf "$0: %s\n" \
"Either \$PYENV_ROOT or \$HOME must be set to determine the install location." \
>&2
exit 1
fi
export PYENV_ROOT="${HOME}/.pyenv"
fi
colorize() {
if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2"
else echo -n "$2"
fi
}
# Checks for `.pyenv` file, and suggests to remove it for installing
if [ -d "${PYENV_ROOT}" ]; then
{ echo
colorize 1 "WARNING"
echo ": Can not proceed with installation. Kindly remove the '${PYENV_ROOT}' directory first."
echo
} >&2
exit 1
fi
failed_checkout() {
echo "Failed to git clone $1"
exit -1
}
checkout(