0

First question - If we have 2 different versions of python(say 2.6,2.7) on the same platform. Can you execute the bytecode (generated with python 2.6 interpreter) on python 2.7 interpreter?

Second question - If we have exact same version of python say 2.7.2 on unix and windows - can you run the bytecode generated on unix machine with the python on windows machine?

Neerav
  • 1,399
  • 5
  • 15
  • 25

1 Answers1

3

Python bytecode is portable across platforms, but not really across Python versions.

Python 2.7 introduced new syntax, for example, resulting in different, new bytecode instructions that Python 2.6 doesn't support. Also see the warning at the top of the dis module documentation:

CPython implementation detail: Bytecode is an implementation detail of the CPython interpreter! No guarantees are made that bytecode will not be added, removed, or changed between versions of Python. Use of this module should not be considered to work across Python VMs or Python releases.

You can move .pyc bytecode cache files across platforms, regardless of word-size and OS.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343