Below is what my project looks like
Project
src
folder1
__pycache__
...
folder2
__pycache__
...
main
__pycache__
tests
__pycache__
...
Is there a way to centralize all the pycache files in one folder so that it looks something like this?
Project
__pycache__
src
folder1
folder2
main
tests
It is not supported to put all cache files under a single subdirectory.
There is an option to put the cache directory tree someplace else, however. Set PYTHONPYCACHEPREFIX:
export PYTHONPYCACHEPREFIX=/path/to/someplace/else
This will create the cached directory tree under /path/to/someplace/else and not litter your project directory with __pycache__ subdirectories.
If you want to disable caching entirely, use PYTHONDONTWRITEBYTECODE instead. Note that startup times will be slightly slower, as Python would have to recompute .pyc files on every startup.
These options may also be specified via interpreter command-line options, -X or -B respectively, rather than via environment variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With