Python: How can I update python version in pyenv-virtual-environment?
Use pip freeze > requirements.txt
to save a list of installed packages.
Create a new venv with python 3.6.
Install saved packages with pip install -r requirements.txt
. When pip founds an universal wheel in its cache it installs the package from the cache. Other packages will be downloaded, cached, built and installed.
Here is how you can switch to 3.9.0
for a given virtual environement venv-name
:
pip freeze > requirements-lock.txt
pyenv virtualenv-delete venv-name
pyenv virtualenv 3.9.0 venv-name
pip install -r requirements-lock.txt
Once everything works correctly you can safely remove the temporary requirements lock file:
rm requirements-lock.txt
Note that using pip freeze > requirements.txt
is usually not a good idea as this file is often used to handle your package requirements (not necessarily pip freeze
output). It's better to use a different (temporary) file just to be sure.