Once in a while I run into a very difficult-to-debug problem: there's a leftover .pyc file somewhere in my $PYTHONPATH, and the matching .py file has been moved to somewhere else that's later in $PYTHONPATH - so when I try to import the module, the "orphaned" .pyc file is used and all changes to the "real" .py file are ignored, leaving me incredibly confused until I figure out that's what's happening.
Is there any way of making python not use "orphaned" .pyc files, or print a warning when using them?
Alternatively, does the fact that I have this problem at all mean I'm doing something wrong, and if so, what?
find * -name '*.pyc' | xargs rm -finstead. Note 1. I usefind *rather thanfind .so that .git etc isn't searched, 2. I delete all pyc files since python appears to only check the source is older than the compiled files, rather than matches the mod time exactly (since it doesn't make the mtime match when creating pyc files - under linux at least).find . -name '*pyc' -delete- apparentlyfindhas a flag for deleting found files