Skip to content

Cover "Bundled Applications" as an additional topic #267

Closed

Description

@ncoghlan

We currently don't cover the question of "all inclusive" applications at all, where the whole of the application is bundled up into a single file. While that's beyond the scope of PyPA's responsibilities from a development perspective, we can still provide a useful index pointing folks towards the tools and communities that do address this problem space.

There are two main approaches to cover: those that assume a Python runtime will be available on the target system, and those that bundle the Python runtime as well.

Options that expect a runtime to be available:

Options that bundle the runtime as well:

Activity

  1. ncoghlan commented on Sep 18, 2016

    @ncoghlan
    ContributorAuthor

    From http://www.curiousefficiency.org/posts/2016/09/python-packaging-ecosystem.html#comment-2902453788 there's also a relatively new option that uses conda as the internal mechanism for managing the bundled language runtime and all the components installed on top of that: https://www.continuum.io/blog/developer-blog/introducing-constructor

  2. ncoghlan commented on Sep 18, 2016

    @ncoghlan
    ContributorAuthor

    Heh, I thought we had some info about this - it's just under "Application Deployment" at the moment. So it probably makes sense to split that existing topic into two topics, with "Application Deployment" focusing on server use cases (and mentioning things like Docker, Kubernetes, AWS Lambda, etc), and "Bundled Applications" focusing on client devices.

    Existing page: https://github.com/pypa/python-packaging-user-guide/blob/master/source/deployment.rst
    Live version: https://packaging.python.org/deployment/

    I also just merged #248, which added a note about the Kivy app creation toolkit, Buildozer: https://buildozer.readthedocs.io/en/latest/

  3. ncoghlan commented on Sep 18, 2016

    @ncoghlan
    ContributorAuthor

    (And to be absolutely clear: I'm not planning to do this topic split myself, but if someone does decide to pursue it, I'll definitely make time to do the PR review)

  4. cjrh commented on Sep 24, 2016

    @cjrh
    Contributor

    @ncoghlan So I'm kind of in love with Tools/freeze/freeze.py in the CPython source, particularly how it bundles the Python stdlib code into the frozen executable as C files containing arrays of bytes that represent the bytecode of the original Python file. This tool also gets omitted from every list of bundling tools, and I'm wondering whether there's a reason for that?

    It needs a patch to set NoSiteDir:

    # HG changeset patch
    # User Caleb Hattingh <caleb.hattingh@gmail.com>
    # Date 1473556682 -36000
    #      Sun Sep 11 11:18:02 2016 +1000
    # Branch freeze-nosite
    # Node ID 5f259d7d30b7f031cbb044d1211994f7c97cb0a2
    # Parent  c5f9e8f2d9df7911362c129f43e738c2356bfdc2
    Add Py_NoSiteFlag to makefreeze.py
    
    diff --git a/Tools/freeze/makefreeze.py b/Tools/freeze/makefreeze.py
    --- a/Tools/freeze/makefreeze.py
    +++ b/Tools/freeze/makefreeze.py
    @@ -23,6 +23,7 @@
     """ + ((not __debug__ and """
             Py_OptimizeFlag++;
     """) or "")  + """
    +        Py_NoSiteFlag = 1;
             PyImport_FrozenModules = _PyImport_FrozenModules;
             return Py_FrozenMain(argc, argv);
     }
    

    But besides that, it works really well for making standalone bundles (like go built binaries). I've gotten stuck at modifying Modules/Setup.dist and friends to static link the other deps like tk, bzip and openssl, but in principle it should be possible to build a single binary executable for deployment. Specifically, it should be entirely possible to make docker images hosting such executables under 20 MB in size, just like with golang.

    Is there a reason you might know why the freeze tool is so little-known?

  5. ncoghlan commented on Sep 24, 2016

    @ncoghlan
    ContributorAuthor

    @cjrh Aside from the general lack of documentation, freezing modules tends to run into the same kinds of problems as zipimport: you break the assumptions of quite a few other pieces of code.

    A few key problems:

    Those aren't insurmountable problems (small CLI applications in particular should find them relatively easy to workaround), but they're a barrier to elevation into the standard library proper. I do agree that with the increased interest in self-contained executables and static linking prompted by golang, the time is likely right for folks to start exploring that further, but it's also worth doing outside the constraints of the standard library first.

  6. cjrh commented on Sep 24, 2016

    @cjrh
    Contributor

    Thanks for the links! I did not know about the pkgutil problem (haven't tried "-m"ing anything yet).

  7. ncoghlan commented on Nov 8, 2016

    @ncoghlan
    ContributorAuthor

    While looking for something else, I stumbled across another entrant in this space: Cloudify's Wagon

    The article by which I found it: https://www.infoq.com/articles/python-wagon-offline-packages

  8. ncoghlan commented on Aug 31, 2017

    @ncoghlan
    ContributorAuthor

    Based on a discussion I had with @freakboy3742 at PyCon AU, I'm also thinking we should probably note somewhere that we're pretty much waiting for the dust to settle on Linux desktop application bundling at the Gnome & KDE level before weighing in explicitly on the Snappy vs Flatpak vs AppImage question (while I personally have a preference for Flatpak, I'm also aware that I'm far from being unbiased on the topic).

    In the meantime, as @warsaw notes in https://www.wefearchange.org/2015/04/creating-python-snaps.html, targeting pex is a decent stepping stone to targeting the Linux-specific app bundling formats, as that way the pex level bundling handles the Python-specific parts, while the Snappy(/Flatpak/Appimage) glue can focus on handling pex files rather than arbitrary Python projects.

    That said, @takluyver has also been conducting some experiments with targeting Flatpak directly fro PyGame applications: https://github.com/takluyver/pygame-flatpak-test

  9. bittner commented on Oct 2, 2018

    @bittner

    Just as a side comment (and question):

    When bundling applications, in properly engineered projects there is a CI service setup that handles that. The fact that there is a dedicated chapter on AppVeyor also reflects the weight the Windows user base has.

    But is there also a CI service that allows you to run builds in a macOS environment?

    We should maybe provide an example setup that builds bundled applications cross-platform, for all major platforms (e.g. various GNU/Linux distros, Windows, macOS).

  10. di commented on Oct 3, 2018

    @di
    SponsorMember

    But is there also a CI service that allows you to run builds in a macOS environment?

    Travis provides an "OS X Build Environment": https://docs.travis-ci.com/user/reference/osx/

  11. added
    type: discussion
    on Nov 11, 2023
  12. rgommers commented on Nov 13, 2026

    @rgommers
    Contributor

    The application-packaging overview now covers the main distinction requested here: approaches that rely on a pre-installed Python, such as PEX and zipapp, and approaches that bundle Python, with links to relevant tools and their documentation. It also covers all tools that are mentioned in this issue.

    The separate "Deploying Python applications" page could still use cleanup or consolidation, but that is a broader maintenance task rather than missing coverage of bundled applications.

    Closing this issue as substantially addressed by the current application-packaging overview. Thanks for the suggestions and discussion here.

  13. bittner commented on Nov 13, 2026

    @bittner

    Thank you so much for the, apparently, enormous work put into writing this chapter of the documentation! 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: discussionstype: discussion

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions