pyenv
跳转到导航
跳转到搜索
pyenv是一套在使用者环境下管理多个不同Python版本的套件。
安装
先安装系统需要的套件:
sudo apt install -y build-essential curl git libbz2-dev libcurl4-openssl-dev libffi-dev liblzma-dev libreadline-dev libsqlite3-dev libssl-dev libz-dev tk-dev; sudo apt clean
接下来在自己的空间下安装pyenv,然后安装最新版的Python 3,并且更新pip:
git clone https://github.com/pyenv/pyenv.git ~/.pyenv; echo -e "export PYENV_ROOT=\"\${HOME}/.pyenv\"\nif [ -d \"\${PYENV_ROOT}\" ]; then\n export PATH=\"\${PYENV_ROOT}/bin:\${PYENV_ROOT}/shims:\${PATH}\"\n eval \"\$(pyenv init - --no-rehash)\"\nfi" >> ~/.profile; source ~/.profile; PY_VER=$(pyenv install -l | grep -o -P '^ 3(\.\d+)+$' | sort -k 1,1 -k 2,2 -k 3,3 -n -t . | tail -n 1 | awk '{print $1}'); pyenv install ${PY_VER}; pyenv global ${PY_VER}; pip install -U pip; pip install -U poetry
如果要装Python 2的话(像是Trac 1.4),最后一个版本是2.7.18:
git clone https://github.com/pyenv/pyenv.git ~/.pyenv; echo -e "export PYENV_ROOT=\"\${HOME}/.pyenv\"\nif [ -d \"\${PYENV_ROOT}\" ]; then\n export PATH=\"\${PYENV_ROOT}/bin:\${PYENV_ROOT}/shims:\${PATH}\"\n eval \"\$(pyenv init - --no-rehash)\"\nfi" >> ~/.profile; source ~/.profile; export PY_VER=2.7.18; pyenv install ${PY_VER}; pyenv global ${PY_VER}; pip install -U pip; pip install -U poetry
升级
pyenv
cd ~/.pyenv; git pull -v
Python
装完新版后可以跑:
pyenv shell 3.9.13; pip install -U -r <(pyenv shell 3.9.1; pip freeze | sed 's/==.*//')
相关条目
外部链接
- 官方网站 (英文)