Currently I use venv and PYTHONPYCACHEPREFIX in most of my projects to keep caches out of source directories. The downside is that I have to track every way Python, tools, or venv-installed commands are invoked. Small mistakes still happen and scatter caches across the project. With automations, cron, and service units, it can even be hard to tell which run caused the pollution. I also set PYTHONPYCACHEPREFIX separately for each venv, which is a maintenance burden because IDEs and other tools do not always let you switch it dynamically without custom wrappers.
My proposal is to extend pyvenv.cfg with a new setting, pycache_prefix, that defines the cache location. It would have the lowest precedence, below the environment variable and the command-line option. It should accept both absolute paths and paths relative to pyvenv.cfg, including forms such as ../var/cache/, given how common it is to place environments in a project’s .venv directory. Because this file is already searched and read at Python startup, the extra cost should be zero for non-venv environments and negligible for venv ones, while giving more convenient cache handling in these deployments.