安装pyenv

项目地址

https://github.com/pyenv/pyenv

安装手册

Home · pyenv/pyenv Wiki (github.com)

安装编译Python所需的依赖

1
$ 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

常见安装错误

Ubuntu 18.04 Pyenv Build Python 3.7 Common Error | Lua Software Code

Common build problems · pyenv/pyenv Wiki (github.com)

使用项目自带脚本安装pyenv

1
$ curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash

写入配置

方法1:命令

1
2
3
4
5
6
7
8
9
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zprofile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zprofile
$ echo 'eval "$(pyenv init --path)"' >> ~/.zprofile

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
$ echo 'eval "$(pyenv init --path)"' >> ~/.profile

$ echo 'eval "$(pyenv init -)"' >> ~/.zshrc

方法2:直接写入文件

1
$ vim ~/.zprofile
# pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
1
$ vim ~/.profile
# pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
1
$ vim ~/.zshrc
# pyenv
eval "$(pyenv init -)"

测试安装

1
$ pyenv -v
pyenv 2.2.3
updatedupdated2022-04-282022-04-28