Are .pyc files portable?

John Machin sjmachin at lexicon.net
Sat Nov 8 09:20:00 EST 2008


On Nov 8, 1:36 pm, Roy Smith <r... at panix.com> wrote:
> I'm using Python as part of a test fixture for a large (mostly C++)
> software project.  We build on a lot of different platforms, but
> Solaris is a special case -- we build on Solaris 8, and then run our
> test suite on Solaris 8, 9, and 10.  The way the build system is set
> up (driven by Build Forge), the Sol 8, 9, and 10 test passes can
> happen in any order.  The tests all run in a common directory, shared
> by NFS on all three machines.
>
> If (for example) the Sol 10 tests run first, and create .pyc files,
> will those .pyc files work correctly when the Sol 8 and Sol 9 test
> passes come along and run them in the same directories?

In general, if the .pyc file is not compatible with the Python binary,
it will be flicked and replaced by compiling the corresponding .py
file if it exists; otherwise you get:
   ImportError: Bad magic number in whatever.pyc

However you appear to be running the same Python binary with different
versions of your OS, so you shouldn't have any problems.



More information about the Python-list mailing list