Delete all '.pyc' files recursively OS X

We often get strange errors with python. When you changing the source and cannot figure out why files are used from past. So if you ever get this dejavu feeling, try using this command:
find . -type f -name '*.pyc' -exec rm {} \;
It will delete all precompiled python sources. (Because with python you have ability to distribute your files in binaries in fact.) Those errors usually appear if you move/delete *.py files with version control. You usually exclude *.pyc files from list. Old links used this way. Debugger does not suggest wrong imports because your files are in fact there, just precompiled.
Anyway I've just put this command to my blog for memorizing. It often helps me. Maybe it can for you.


  1. I came here to read your article on using South, and found this. It's almost identical to my own setup, except I have it as a bash alias, also delete .pyo files, and use xargs for speed. If you're interested it's:

    alias pyc='find . \( -iname \*\.pyc -o -iname \*\.pyo \) -print0 | xargs -0 rm -f'

  2. для Ubuntu Тоже канает. Добавил алиас в .bashrc и работает.

  3. A slightly modified version that removes files in bulk, as in: "rm file1 file2 file3" instead of "rm file1; rm file2; rm file3".

    find . -name \*.pyc -exec rm \{\} \+


Post a Comment

Popular posts from this blog

Run Flask with Debug in PyCharm

Python converting PDF to Image

Django: Resetting Passwords (with internal tools)