[Fixed]-Why was an old .pyc file breaking Django?

11👍

No, in fact, Python will use the .pyc file preferably and only access the .py file if it a) exists and b) is newer than the .pyc file.

This allows you to distribute a Python app in compiled form without the source code (although it’s not much of a code “obfuscation” technique).

9👍

Nope, Python is (intentionally, see below) dumb about this! You can run

find . -name '*.pyc' -delete

from your project directory to get rid of old .pyc files.

If you’re using git, you can set up a hook to do this automatically on checkout. Here’s a similar solution for Mercurial.

2👍

The thing you can do to prevent this is to start django with

python -B manage.py runserver

or to automate deletion of pyc, probably with clean_pyc from django-extensions

./manage.py clean_pyc

Leave a comment