Search code examples
pythonflask

How to avoid __pycache__ when using flask?


I see __pycache__ is alawys generated in the following example. Is there a different way use flask to avoid __pycache__ from being generated?

https://flask.palletsprojects.com/en/1.1.x/quickstart/


Solution

  • This is not a Flask thing, but rather a Python one. The __pycache__ dir is used to store the bytecode ("compiled" versions) of your source (.py) files (mostly, for performance reasons). Python 3 does that by default. To suppress the behavior, pass the -B argument to the interpreter, as pointed out by: [Python.Docs]: Command line and environment - -B:

    If given, Python won’t try to write .pyc files on the import of source modules. See also PYTHONDONTWRITEBYTECODE.

    Or (if you run flask.exe directly), set the PYTHONDONTWRITEBYTECODE env var, to something different than empty (set PYTHONDONTWRITEBYTECODE=some_dummy_text), before starting the interpreter.