I would like to have multiple virtual environments, some with a different python version itself. I am uncertain about the base version of the python I should use. For instace, if I create venv
dependent virtual environments using python provided by my current Ubuntu OS, say 3.8, and later I upgrade Ubuntu itself and that updates python to version 3.10, will the virtual environments created under previous Ubuntu still work?
3
Answers
The way venvs work is that they bring along a whole Python runtime with them. Indeed if you activate the venv and then run
which python
you will not see your system Python, but the one installed by the venv.In that way, if you upgrade your OS and that also upgrades your system Python, you won’t have to worry because your venv will still have the old version vendored in place.
virtual environment essentially copy from OS installation to the venv, so you will be maintainint all the libraries in the venv folder.
When you upgrade the OS the binaries will stay there and you will have both version available in different venv
Virtualenvs do depend on their base interpreter being intact.
If the OS upgrade (or any other process) removes, say,
python3.8
, then no, venvs whose base interpreter is thatpython3.8
won’t work anymore.To demonstrate this in a Docker container, let’s install Python 3.10 and 3.11, create venvs with both of them, then remove one base interpreter to see that the respective venv no longer works: