如何用pyenv更新Python版本(3.6.2至3.6.5)及操作步骤咨询
Hey there! Your core approach is totally on the right track—let me break this down into a streamlined, error-proof process with some handy tips to make it smoother:
First, install the new Python version
Start by installing Python 3.6.5 via pyenv, just as you thought:pyenv install 3.6.5If you want to confirm 3.6.5 is available (in case of any minor delays in the pyenv repo), you can list all available 3.6.x versions with:
pyenv install --list | grep 3.6Export your existing package list
Before switching, grab a snapshot of all packages in your 3.6.2 environment. First activate the old version:# Use `pyenv global 3.6.2` if it's your system-wide default pyenv local 3.6.2Then export the packages to a requirements file:
pip freeze > requirements.txtSwitch to the new environment and install packages
Activate your freshly installed 3.6.5 version:# Use `pyenv global 3.6.5` for system-wide use pyenv local 3.6.5It’s smart to upgrade pip first in the new environment to avoid compatibility hiccups:
pip install --upgrade pipNow install all your old packages from the requirements file:
pip install -r requirements.txtVerify everything works
Run your projects, scripts, or tests in the 3.6.5 environment to make sure all dependencies function as expected. Don’t skip this step—better safe than sorry!Uninstall the old version (optional)
Once you’re confident the new environment is stable and you no longer need 3.6.2, you can remove it:pyenv uninstall 3.6.2Just double-check that no existing projects are still configured to use 3.6.2 before deleting it.
Quick note for pyenv-virtualenv users
If you’re using virtual environments tied to specific Python versions, create a new virtualenv for 3.6.5 first, then repeat the requirements export/import steps into that new virtualenv instead of the base 3.6.5 environment.
内容的提问来源于stack exchange,提问作者adamstueckrath

