When I install a python deb package, say python-numpy
the files are plain python files. How do I tell to the package manager -- that I actually would rather use pyc or even better -- pyo files?
When I install a python deb package, say python-numpy
the files are plain python files. How do I tell to the package manager -- that I actually would rather use pyc or even better -- pyo files?
You already have them and you're already using them
Well-packaged Python applications are being compiled to
.pyc
files in a script run after installation of the files has taken place. This is needed according to the packaging guidelines to be able to adopt to the Python installation you're using at that moment. Do remember that.pyc
files are very specific to your system (Python version and dependencies).All
.pyo
and.pyc
files are therefore specifically excluded in packages and tagged as errors by Lintian:In the case of
python-numpy
this post-install byte-compilation is handled by the debhelper hook of pycentral. After installation it looks like this:Some more background information
The reason for why these
.pyc
/.pyo
files aren't compiled at runtime during the first application startup as you expected is the following.The Python files are installed in a system-wide directory, available for all users on the system. Whenever a user starts the application, the Python interpreter can read the
.py
files, but it can't write to the directories (e.g./usr/lib/python2.7/dist-packages/
). This is part of general security in all Linux systems; users shouldn't write to/usr
, only with root rights this should be possible. For this reason, the APT hooks will compile the Python files for you at installation time; firstly to minimize the package size, secondly to be able to retrigger the hooks once something changes on your system regarding Python, because it's required to recompile when they get incompatible during upgrades for example.This won't, however, affect regular user-owned python files being compiled at runtime.