Eliminate Python 3.8+ __pycache__ directories
Python 3.8 brought the capability to put Python cache files under __pycache__/
anywhere.
Control this behavior by setting the
PYTHONPYCACHEPREFIX
environment variable.
Example
- Windows: set environment variable PYTHONPYCACHEPREFIX to %temp%
- MacOS:
export PYTHONPYCACHEPREFIX=/tmp
- Linux:
export PYTHONPYCACHEPREFIX=/tmp
Workaround
Python older than 3.8 can avoid writing .pyc files anywhere by setting environment variable:
PYTHONDONTWRITEBYTECODE=1