A .pyc file is an 8-byte header followed by a code object marshalledby marshal.dump(). Since the code object contains the pathname of the .py file from which it was created, .pyc files on different systems may be different unless the pathname used on both systems is identical.
The header format is trivial: the first 4 bytes are a magic number used to distinguish incompatible interpreters (currently 0x999902L -- see the definition of MAGIC in Python/import.c) followed by 4 bytes which give the mtime of the .py file from which the .pyc file was generated. Byte order is LITTLE-ENDIAN (lsb first).
If the .py file exists (in the same directory) and its mtime does not match, the .pyc file is ignored and rewritten (silently). Note that the filename from the code object is not used for the comparison - in order to match, the .py and .pyc file must have the same name and live in the same directory.
Originally from: http://www.python.org/search/hypermail/python-1994q1/0308.html