Update on python virtual environment management

In the past I wrote about how I use pyenv to manage virtual environtment, see here, and althought I was very happy with it I have changed the way I manage venvs.

There have been two main reasons for this change. First almost all the repositories I work with have been introducing poetry and this somehow has broken some of those pyenv virtualenv automatic integration. Secondly, the pipelines of those repos are automated assuming a venv directory exists in the directory.

Although one could argue that the process to update the local pipeline is always the same and it is rather simple, I prefer to run a set up as close to production or ci pipelines as possible. So I updated my methodology.

Creating venvs with desired version

I still use pyenv to manage different python versions, but I no longer use it to manage every single venv. Each venv is created with:

/home/user/.pyenv/versions/3.12.3/bin/python -m venv .venv

Here we run the desired python version (must be installed with pyenv first) to create a venv.

Basic poetry commands

Activating venv as usual:

source .venv/bin/activate

Install dependencies:

poetry install

Adding a new dependency:

poetry add numpy

Updating all dependencies on the lock file:

poetry lock

Note that after updating the lock the depencides must be installed.