Python: How can I update python version in pyenv-virtual-environment?
Solution 1
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.
Solution 2
Here is how I switched from 3.9.0a5
to 3.9.0
:
$ pip freeze > requirements-lock.txt
$ pyenv virtualenv-delete a-virtualenv-name
$ pyenv virtualenv 3.9.0 a-virtualenv-name
$ pip install -r requirements-lock.txt
$ rm requirements-lock.txt
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.
Related videos on Youtube
user3595632
Updated on September 16, 2022Comments
-
user3595632 over 1 year
I used
pyenv
,pyenv-virtualenv
for managing python virtual environment.I have a project working in
Python 3.4
virtual environment.So all installed packages(
pandas
,numpy
etc) are not newest version.What I want to do is to upgrade
Python
version from 3.4 to 3.6 as well as upgrade other package version to higher one.How can I do this easily?
-
Vadim almost 7 yearsmaybe create a new virtual environment?
-
-
Andron over 3 yearsThis is a better solution, especially if requirements.txt is checked into version control.
-
jsbueno about 3 yearsplease note that this is not a "downgrade" -
3.9.0a5
is an alpha release of Python, while3.9.0
is the final, stable, release of the version.