Skip to content

Should compiled bytecode (__pycache__/*.pyc) be bundled with the AppImage? #91

@mxmlnkn

Description

@mxmlnkn

Hello,

This is more of a question than an issue. Maybe someone here knows the answer.

Should compiled bytecode (.pyc) be bundled with the AppImage?

I have never heard of bugs caused by accidentally bundling bytecode or having some bytecode leftover after updates. I would assume that it is simply ignored or regenerated when there are incompatibilities. The glossary states:

This “intermediate language” is said to run on a virtual machine that executes the machine code corresponding to each bytecode. Do note that bytecodes are not expected to work between different Python virtual machines, nor to be stable between Python releases.

To me, this seems to imply that everything should be fine as long as the same Python binary is used, which is the case for an AppImage bundling it.

Some solutions such as PyInstaller seem to always bundle the bytecode and even offer to remove the original source code.

So, would it not make sense to bundle it to reduce startup times? Else, it might try to compile the .py files on each AppImage start.

Even if it would not make sense to bundle it, should the -B option be used for the Python interpreter so that it does not even try to write out .pyc files somewhere? As far as I know, the AppImage is mounted on a read-only file system, so it shouldn't matter much, except maybe some failed write syscalls. It may make a difference when running the extracted AppDir via AppRun, but I guess then it would be desired to create the __pycache__ / .pyc files. It might also not make sense when not using the isolated mode.

It seems that a normal pip install inside the AppImage already creates .pyc files, but my build script deleted them with find "$APP_DIR" -name '__pycache__' -print0 | xargs -0 rm -r to optimize the AppImage size, I suppose. But, I assume that this only creates .pyc files for actually imported modules. It seems inconsistent to have some modules compiled and some not. Ergo, should all the .pyc be deleted, or should I run compileall?

It seems that the AppImages in the Releases section do not contain any .pyc files. However, as the instructions in the "Advanced Installation" section probably result in some .pyc files being created, something should be suggested there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions