how to get rid of pyc files ?

Gabriel Genellina gagsl-py2 at
Tue May 26 09:20:11 CEST 2009

En Mon, 25 May 2009 17:00:00 -0300, <pythoncurious at> escribió:
> On May 25, 12:08 am, Dave Angel <da... at> wrote:
>> Somebody else has already pointed out that you can tell Python not to
>> create thosefiles(during your development stages).
> Yes, that's probably the best way to sort out the problems.
> It would of course be nice if python could detect that these files
> aren't usable and just regenerate them. I realise it might not be a
> trivial feature to implement though.

.pyc files are platform independent; you *can* use the same .pyc files
both on Windows and Linux.
A .pyc/.pyo file contains two bits of info:
- a magic number that depends on the Python version that created it
- the last-modification-time of the corresponding .py source
When you import a module, both numbers are read from the .pyc file. If the
magic number matches the version of the running Python, and the
modification time matches the one of the .py file (or no .py file exists),
then the .pyc file is used. In any other case, the .py file is read,
compiled, and a .pyc file is written -- if possible.

So, if you ensure that both platforms "see" the same
last-modification-time, and you use the same Python version on both
platforms, then .pyc files may be shared. If not, each time you switch
platforms all .pyc files will be re-created (option -B avoids that, as
already noted).

I any case, I don't think leaving the wrong .pyc files should create any
problem (except some delay when the application starts, and unless you've
found a bug, of course)

Gabriel Genellina

More information about the Python-list mailing list