How can I upgrade the current Python
interpreter inside a venv
to v3.7.1. Unfortunately 3.5.2 is out of date for some libraries I use, so I want to switch to 3.7.1.
Option 1: is to update the interpreter inside my venv.
Option 2: is to create a new venv with Python 3.7.1 as its interpreter and deploy the whole project with all its dependencies and tweaks anew?
What is the typical way to port a Flask application to a newer interpreter?
Much the easiest way is to create a new venv.
If you don't have a requirements.txt
file in your app, now's the time to generate one and commit it into your version control software (Git, Mercurial etc). With the old venv activated:
>>> pip freeze >requirements.txt
Create the new venv with the desired python version and give it a name:
>>> virtualenv -p python3.7 venvname
Activate the venv:
>>> source venvname/bin/activate
Then install your requirements:
>>> pip install -r requirements.txt
should set the new venv up exactly as the old one was, give or take the odd version conflict. Fix those conflicts and rerun pip install -r
until there are no more errors.
It's worth testing against this new temporary venv until you're sure enough to delete the original and recreate it on Py3.7.
In general if you're interested in renaming the venv, there are further details in this question but it's not advised.
Depending on the version you're upgrading from, it might be useful to know that Python 2 end of life was Jan 2020 and Python 3.5 was Sept 2020 (more details). If you have a choice (and if it matters) it's safer and more secure to use a version of Python that is still supported.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With