Python venv setup no longer working as expected, build failing

Hello,

My Django project builds have started failing as of Friday, Sept 23 2022.

This is the error that I receive:

#!/bin/bash -eo pipefail
python -m venv venv
. venv/bin/activate
pip install --upgrade pip
pip install -r src/development.txt

Error: [Errno 2] No such file or directory: '/home/circleci/repo/venv/bin/python'

Exited with code exit status 1
CircleCI received exit code 1

The excerpt of my config.yml file:

- restore_cache:
    keys: v2.1-dependencies-{{ checksum "src/requirements.txt" }}
- run:
    name: Install Python dependencies in the venv
    command: |
        python -m venv ./venv
        . venv/bin/activate
        pip install --upgrade pip
        pip install -r src/requirements.txt
- save_cache:
    key: v2.1-dependencies-{{ checksum "src/requirements.txt" }}
    paths:
        - "venv"

This is almost identical to the steps outlined in the documentation here:

Note: I do have a workaround, which involves changing one of the commands to:

rm -rf venv && python -m venv venv

This seems to defeat the purpose of caching though if I remove the venv directory every time.

Any thoughts or help would be appreciated. Thanks.

hi @eorfan ,

without knowing your job’s full definition, I am unable to tell how your job’s execution environment is set up.

For example, is this using a Docker image, and if so, what is the Docker image used?
It may be that depending on how you specify the Docker image (and tag), you may be pulling a newer Docker image that likely has some changes there.

However, from the limited information above, I’d suspect the Python runtime version (provided in your execution environment) has been updated.

I understand that with Virtualenv, a pyvenv.cfg file is created, and that may store the Python runtime version then.
I see that you are caching the entire venv folder, which includes this file.

As such, can you try “bursting” the cache, and see if it resolves for you?
(I.e., change the cache key)

- restore_cache:
    keys: v2.2-dependencies-{{ checksum "src/requirements.txt" }}
- run:
    name: Install Python dependencies in the venv
    command: |
        python -m venv ./venv
        . venv/bin/activate
        pip install --upgrade pip
        pip install -r src/requirements.txt
- save_cache:
    key: v2.2-dependencies-{{ checksum "src/requirements.txt" }}
    paths:
        - "venv"