Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: uv bundle, uv build --release or similar to create a contained executable a la pyinstaller, py2exe #5802

Open
matterhorn103 opened this issue Aug 5, 2024 · 9 comments
Labels
wish Not on the immediate roadmap

Comments

@matterhorn103
Copy link

matterhorn103 commented Aug 5, 2024

I regularly use pyinstaller for a project, and the frequency of questions about it - or the task more generally of "compiling" an executable for distribution - around the web indicates to me that it's widely popular.

It would be incredibly cool if uv offered a uv bundle command (or whatever name) that essentially did what pyinstaller does and bundles together everything to afford an executable that contains the dependencies and interpreter and can be distributed to users as-is. And I think this falls into the realm of what things a "Cargo for Python" might be expected to be able to do.

I assume that pyinstaller, py2exe etc. are complex projects and implementing such functionality would be not trivial in the slightest, so I would have thought it would be a case of using pyinstaller itself in the background like the way that build backends are used.

Presumably there will one day be a uv build command but I assume that will be similar to rye build in that it will create an sdist or wheel. Maybe there could be a uv build --executable option, or uv build --release (by analogy to cargo build --release)?

@matterhorn103 matterhorn103 changed the title Suggestion: uv bundle or similar to create a contained executable a la pyinstaller, py2exe Suggestion: uv bundle, uv build --release or similar to create a contained executable a la pyinstaller, py2exe Aug 5, 2024
@matterhorn103
Copy link
Author

matterhorn103 commented Aug 6, 2024

Some relevant links that I'm adding to keep track of them for myself as much as anyone else:

  • It seems someone asked for the same in Rye previously
  • ofek's PyApp and Gregory Szorc's (indygreg) now-dead PyOxidizer are other, more modern executable generators that I didn't know about until now; both seem simpler than pyinstaller, and both are written in Rust
  • Gregory Szorc once did a comparison of the various alternatives to PyOxidizer
  • One missing from that list, presumably because it's not generally applicable, is the pyside6-deploy tool, but it uses Nuitka in the background in any case
  • Hatch seems to have implemented essentially this functionality, as part of a Hatch plugin that uses PyApp, and it is invoked there by having "binary" as a build target

@zanieb zanieb added the wish Not on the immediate roadmap label Aug 6, 2024
@chrisrodrigue
Copy link

To add… despite its popularity, pyinstaller suffers from slowness because has to unzip all the dependencies and the interpreter when the executable is launched. It offers users the option to display a splash image to distract them from the perceived slowness.

@chrisrodrigue
Copy link

chrisrodrigue commented Aug 6, 2024

Python to Rust transpilation would be pretty cool and there’s at least one project out there working on this:

Imagine writing idiomatic Python, transpiling it to Rust and compiling a native executable. My mind would be blown.

I don’t know how one could gracefully handle dependencies though. A lot of Python libs incorporate C extensions. Dealing with those would be extremely difficult, but there’s a DARPA program called TRACTOR working on that.

@paveldikov
Copy link
Contributor

An equivalent of pyinstaller that actually understands standard pyproject.toml-driven projects and console/GUI script entrypoints (instead of being fixated on script development, and overcompensating with its dependency detection magic) would be huge.

(somewhat related: #5653)

@my1e5
Copy link
Contributor

my1e5 commented Aug 7, 2024

I want to give a mention to Nuitka which is serving me well. It's as straightforward as running

uv add --dev nuitka
uv run python -m nuitka --standalone src/main.py

which spits out an executable.

It's not really the right tool to be including with uv, it is essentially an alternate Python interpreter which compiles Python to C. But it's very easy to add and has worked well for me. And my experience with the developers has been very good. They were quick to add support for Rye when I encountered bugs - Nuitka/Nuitka#2933

@matterhorn103
Copy link
Author

@my1e5 why do you say that Nuitka would be unsuitable for inclusion with uv?

@my1e5
Copy link
Contributor

my1e5 commented Aug 27, 2024

@matterhorn103, I guess what I mean is that Nuitka is perhaps quite an opinionated way of packaging your Python code into an executable - as it is essentially an alternate Python interpreter which compiles Python to C. Whereas tools like Pyinstaller are more like a bundler - taking the Python interpreter, Python files and dependencies and packaging them into an executable. This is definitely more straightforward than the Nuitka approach, but it does make the Pyinstaller executable very easy to un-package and see the underlying source code (see https://github.com/extremecoders-re/pyinstxtractor). Which might be a caveat needed when including certain 'executable creators' within uv - you need to make users aware that their exe can easily be un-packaged.

In terms of licensing, Nuitka is MIT licensed. But it does also have a commercial tier - which may or may not complicate matters if Astral were to want to bundle it with uv, I don't know.

@zanieb
Copy link
Member

zanieb commented Sep 3, 2024

I think this is a duplicate of #2799, though there's more discussion here.

@martimlobao
Copy link

Also want to call out pex, a tool for generating .pex files (Python EXecutable) which are self-contained zipped executable Python environments containing sources, requirements, and dependencies.

https://github.com/pex-tool/pex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wish Not on the immediate roadmap
Projects
None yet
Development

No branches or pull requests

6 participants