Gangmax Blog

Pyenv migration

When installing a new Python version with pyenv, you may need to migrate all the installed packages from a previous Python version to the new one. For an example, I had Python 3.5.2 and installed a lot of packages with pip. After I install Python 3.6.0, I want to make the new Python have all the packages under the Python 3.5.2 version.

Just need to run the following commands:

1
2
3
4
5
6
7
8
9
10
# Switch to Python 3.5.2 version.
pyenv global 3.5.2
# Save the installed package list.
pip freeze > all.txt
# Switch to Python 3.6.0 version.
pyenv global 3.6.0
# Install the packages in the list.
pip install -r all.txt
# Chech the installed packages.
pip list

Actually “pyenv” provides an “pyenv-pip-migrate“ plugin to do the same thing but it needs to be installed separately, and the plugin uses the same commands above. So I think it’s more easier to use the commands directly.

Comments