Stop pyc files from being generated during development

29 Sep 2014  Posted under: python , programming

CPython generates .pyc files, which contain byte code that has been compiled by the interperter. But these can be annoying as they clutter up your directories while you are trying to do development. An easy way to prevent them from being generated by your testing scripts is to include the following lines at the top of your executable (and remove it before you release the code).

#!/usr/bin/env python
import sys
sys.dont_write_bytecode = True

An alternative method that is more temporary is to set the PYTHONDONTWRITEBYTECODE environment variable.