I installed Python3.10 and I have a venv in a project I have been working on. I don't understand how to upgrade this easily. My background is mostly in Node and JS which is must simpler and more straightforward to change versions.
I was just trying to create a new venv but that didn't work
mpaccione@T430:~/Projects/investing/react-flask-app/server$ python3.10 -m venv ~/Projects/investing/react-flask-app/server
Error: Command '['/home/mpaccione/Projects/investing/react-flask-app/server/bin/python3.10', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
I also thought maybe I could change the pyvenv config could be changed but that didn't work either
home = /usr/bin
include-system-site-packages = false
version = 3.8
to
home = /usr/bin/python3.10
include-system-site-packages = false
version = 3.10
Is there just a simply straightforward way to change this? I'm sure it's a common use case!
Locating in the directory with code.
Assuming ~/Projects/investing/react-flask-app/server for you.
Activate venv if it isn't (assume, venv using for current virtual environment):
$ source venv/bin/activate
Save your current dependencies:
$ pip freeze > requirements.txt
Deactivate current virtual environment:
$ deactivate
Delete the current venv folder (I don't how it is called in your machine).
Create a new venv folder (if python3.10 using for Python 3.10):
$ python3.10 -m venv venv
Activate venv:
$ source venv/bin/activate
Install saved dependencies:
$ pip install -r requirements.txt
According to the official docs venv has an --upgrade command, so if your interpreter-hook of the most current version is python3.10, it should be:
python3.10 -m venv --upgrade ~/Projects/investing/react-flask-app/server
However, it might be that this fails because your hook-alias changed and that the python installation is different from the one used to create the venv. From the docs regarding --upgrade:
Upgrade the environment directory to use this version of Python, assuming Python has been upgraded in-place.
I would recommend to simply store the dependencies in a requirements.txt file, delete the venv, and recreate it with the new python version to make a clean new venv:
python -m pip freeze > requirements.txtpython -m pip install -r requirements.txtIf 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