foreword

install pyenv

  • Install dependencies
sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
  • Install
# git 克隆
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
# 编译加速(可选)
 cd ~/.pyenv && src/configure && make -C src
  • Add in ~/.profile
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
# 没有这句,下面的镜像 url 不生效
export PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM=1
# 国内 Python 镜像
export PYTHON_BUILD_MIRROR_URL="https://mirrors.huaweicloud.com/python/"
# OR
export PYTHON_BUILD_MIRROR_URL="https://npm.taobao.org/mirrors/python/"
eval "$(pyenv init --path)"
  • Add in ~/.bashrc
eval "$(pyenv init -)"
  • restart the shell
exec $SHELL

Basic usage of pyenv

  • View Installable Python Versions
pyenv install -l
  • Install the specified version of Python
pyenv install 3.9.12 -v
  • View installed Python versions
$ pyenv versions
* system (set by /home/qbit/.pyenv/version)
  3.6.15
  3.9.12
  • Switch Python version
pyenv global 版本号  设置当前全局python版本
pyenv local  版本号  设置局部python版本
pyenv local --unset  取消局部python版本设置,或者删除当前目录下的.python-version文件
This article is from qbit snap

qbit
268 声望279 粉丝