Archive
Posts Tagged ‘pycache’
How to avoid *.pyc files?
March 23, 2013
Leave a comment
Problem
Your project directories are littered with .pyc files. How to tell the interpreter to stop creating them?
Solution
Since Python 2.6:
“Python can now be prevented from writing .pyc or .pyo files by supplying the -B switch to the Python interpreter, or by setting the PYTHONDONTWRITEBYTECODE environment variable before running the interpreter. This setting is available to Python programs as the sys.dont_write_bytecode variable, and Python code can change the value to modify the interpreter’s behaviour.” (tip from here)
So I added the following lines to my .bashrc file:
# don't create .pyc and .pyo files PYTHONDONTWRITEBYTECODE=True export PYTHONDONTWRITEBYTECODE
Python 3.2 can save .pyc files in a dedicated subfolder called “__pycache__“.
