[Python-Dev] Inconsistent behaviour in import/zipimport hooks
Guido van Rossum
guido at python.org
Mon Nov 14 14:23:57 CET 2005
On 11/14/05, Ulrich Berning <ulrich.berning at desys.de> wrote:
> >You seem to forget the realities of backwards compatibility. While
> >there are ways to cache bytecode without having multiple extensions,
> >we probably can't do that until Python 3.0.
> >
> Please can you explain what backwards compatibility means in this
> context? Generated bytecode is neither upwards nor backwards compatible.
No, but the general format of .pyc/.pyo files hasn't changed since
1991 (magic number, timestamp, marshalled data) and while the magic
number has changed many times, the API for getting it has been stable
for probably 10 years. Lots of tools (you mention a few) have been
written that read or write these files and these would all to some
extent have to be taught by the changes (most likely the changes will
include a change to the file header).
> No matter what I try, I always get a 'Bad magic number' when I try to
> import bytecode generated with a different Python version.
> The most obvious software, that may depend on the existence of .pyo
> files are the various freeze/packaging tools like py2exe, py2app,
> cx_Freeze and Installer. I haven't checked them in detail, but after a
> short inspection, they seem to be independent of the existence of .pyo
> files. I can't imagine that there is any other Python software, that
> depends on the existence of .pyo files, but maybe I'm totally wrong in
> this wild guess.
It's not just the existence of .pyo files. It's the format of the .pyc
files that will have to change to accommodate multiple versions of
bytecode.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list