pyenv

出自Gea-Suan Lin's Wiki
跳至導覽 跳至搜尋

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/==.*//')

相關條目

外部連結