Python .pyc and .pyo files

Bug #163109 reported by Johannes Meixner on 2007-11-16
Affects Status Importance Assigned to Milestone
David Suffield

Bug Description

When I build HPLIP for openSUSE, I use in the RPM spec file
./configure --prefix=/usr \
 --libdir=%_libdir \
 --disable-foomatic-xml-install \
 --enable-foomatic-ppd-install \
 --with-hpppddir=%{_datadir}/cups/model/manufacturer-PPDs/%{name} \
 --with-cupsbackenddir=%{_libdir}/cups/backend \
make install DESTDIR=%{buildroot}

This results all Python .py files to be installed under /usr/share/hplip/

Neither .pyc nor .pyo files are compiled or installed.

All python files should be under /usr/lib[64]/pythonx.y/site-package
e.g. /usr/lib[64]/python2.5/site-packages/hplip/

Because this directory is both architecture and Python version
dependant, a configure option like --with-pythondir=DIR
is required so that one can use in the RPM spec file

The current directory /usr/share/hplip/ leads to problems.

Byte-compiled Python .pyc and .pyo files can differ for
different major versions of Python.
If one upgraded to a new major version of Python, it would
report errors about bad bytecode, and I don't know if Python
would recompile automatically.
Therefore Python has versioned site-packages.

It would be good to create byte-compiled Python .pyc and .pyo files
by default (preferably via a configure option like
--enable-byte-compiled-python which is by default enabled)
and install them because this speeds up loading of Python modules.

Only if root runs HPLIP's .py files, Python can create the
matching .pyc and .pyo files and store them where the .py files are
because only root has write access where the .py files are.
As long as root doesn't run HPLIP's .py files, Python would need
to compile the sources every time the program is run.

This has another consequence:
It doesn't help not to provide .pyc or .pyo files in the RPM
to avoid problems with outdated .pyc or .pyo files.
When root runs .py files, the matching .pyc or .pyo files
are created in any case.
If later there is a Python major version upgrade
and a normal user runs the outdated .pyc or .pyo files,
it would not help when Python tries to recompile them
because a normal user cannot write the new .pyc or .pyo files.
Hopefully Python will use then the .py files as fallback
but I don't know if it does.

Johannes Meixner (jsmeix) wrote :

You may like to have a look at the
"How to deal with Python .pyc and .pyo files?" thread on the
<email address hidden> mailing list,
in particular see

Put on the todo list, assigning to Don.


Changed in hplip:
assignee: nobody → dwelch91
importance: Undecided → Medium
status: New → Confirmed
dwelch91 (dwelch91) on 2009-07-30
Changed in hplip:
assignee: dwelch91 (dwelch91) → David Suffield (david-suffield)
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers