Alternative to Python executable application for all types of env
Posted by DracoEmperor2003@reddit | Python | View on Reddit | 29 comments
Hi, so any .exe application generated from python is easier to run on windows right? for Linux and MacOS we have run it on virtual environment. But is there any other way to pack it in a environment friendly way? I don't have an UI, it's a CLI application.
Thank you for your responses in advanced.
maqnius10@reddit
How abiut making a proper python package and using pip install with your system python on the machines to integrate it?
DracoEmperor2003@reddit (OP)
OHHH!! is that possible???? will check this out, seems interesting
LeviathanP@reddit
Are you using a package manager, or just pure python + pip? Some package managers make it really easy to do that. For example, with poetry you can just run `poetry build` and it will generate a .whl file, which you can either upload to pypi or distribute to the users, who can then install it with `pip install package.whl`.
Though I'm not sure if dependencies are included in the .whl package. If your app has dependencies, you might wanna test if users have to install them separately.
maqnius10@reddit
Yes, this might be helpful https://packaging.python.org/en/latest/guides/creating-command-line-tools/
syklemil@reddit
Sure. Check out
uv; you can init stuff likeuv init --app --package $nameand install it withuv tool install $name_or_path._MicroWave_@reddit
i think building into binary executables never really works well.
Better off packaging your tool and then use 'uv tool' to distribute it.
Python isnt a compiled language so dont make it one.
riscbee@reddit
https://pyinstaller.org/
DracoEmperor2003@reddit (OP)
It says to make windows app, on windows and for Linux on Linux. I'll have to request a Linux VM for this. But is there a way that I can make it environment dependent from windows itself?
KROSSEYE@reddit
I use docker containers with PyInstaller to build binaries of my programs. The windows one uses WINE to build for windows on Linux (windows Python installed through WINE).
grimonce@reddit
No, cross compilation or in this case 'crosspacking' is a complicated topic. Don't know it nuitka supports this, pretty sure pyinstaller doesn't.
Some like golang or C or rust have a toolchain that supports such efforts, here you will have to prepare one thing on Linux and another on Windows.
riscbee@reddit
You‘re looking for ‘cross compiling’. And you are somewhat reinventing the wheel. Python is platform independent because the Python interpreter does the heavy lifting and your source code becomes platform independent. But you want to create a single binary executable and that comes with all the hassles of cross compiling and packaging. I’m not aware of such a project for Python. I’ve only used pyinstaller once. But since you’re in Windows maybe using WSL is an option?
Drevicar@reddit
I’m a huge fan of https://nuitka.net/ for compiling Python to a binary executable (rather than bundling your code and an interpreter together into a zip), where it is applicable.
DracoEmperor2003@reddit (OP)
okayyy will check this aswell!
zangler@reddit
Make it Java?
Sorry... couldn't resist
DracoEmperor2003@reddit (OP)
😭 I mean yes, even my higher ups are suggesting me that, but re-coding everything in Java again....
zangler@reddit
Use Koltlin then and get good with AI assistance to convert. Basically use this as an opportunity to accelerate your ability to perform such things in reasonable periods of time. Apply rigid levels of QA. The company will benefit and you will have a modern skill set most won't.
Don't believe ANYTHING anyone says about not trusting AI assistance I'm coding. They literally have no idea. Problem is there is so much crap is that most assume it is all crap. The others use it a bit...find mistakes and assume practice isn't related to speed and quality.
Source: this year released over 400k lines in a fortune 250 company with full and complete human code reviews and scientific peer reviews leveraging python, Java, HTML, SQL, shell. All stress tested and enterprise grade...but it took WORK to correctly understand.
predictions: tons of down votes... bullshit about lines of code blah blah... reddit is reddit.
440Music@reddit
Converting between languages is one of AI's greatest strengths, since it's all basically mapping from one documentation set to another. No creative thinking required. Anyone who sends some functions through an LLM to get a "programming language B" version should immediately see the utility.
DracoEmperor2003@reddit (OP)
that's actually so cool! and yes I am leveraging ai myself haha it's all about prompts and people tend to vaguely prompt and then say AI is not helping.
Thank you will try this out, converting to Java or Kotli n.
zangler@reddit
Let me know how you make out. I do 95% in VSCode with GH Copilot...I don't do agents released on the code base trying to one shot shit or anything like that. All of the code we work on is on me...so I treat it like I'm reviewing a PR. It is exactly as exhausting as an extended coding session...but a realistic 5x? Depending on the task... easily more.
LeviathanP@reddit
You've got a few good answers already, so let me just say that, if your problem is that you do not have a linux/mac/windows machine to generate the executable, you can use GitHub Actions instead. For example, with nuitka: https://github.com/Nuitka/Nuitka-Action
DivineSentry@reddit
You can’t do cross compilation but you can generate executables that work per platform using Nuitka, alternatively you can ask your users to download uv and set up your project so that they can run your script easily as uv can download the Python interpreter, the dependencies and run the scripts easily with a single command
DracoEmperor2003@reddit (OP)
noted!
airen977@reddit
Wasm?
DK09_@reddit
You question has your answer. How do you generate executable in windows? Can you do it in Linux too?
DracoEmperor2003@reddit (OP)
i mean can I make it cross compilable from windows environment itself!
DK09_@reddit
Sadly, nope
DracoEmperor2003@reddit (OP)
:') okay! thank you
knellotron@reddit
Well, .exe IS a windows executable, so it's easy for Windows. The tool that you used to make that executable can also generate executables for other operating systems if you run set up your environment on whatever OS you like, and run it there. I use Nuitka for most projects these days.
Cross-compiling (using one OS to compile for another) is a pretty common thing too, but that requires a little more setup.
Illustrious-Reward-3@reddit
PyInstaller. It's not perfect but it fits the bill. Im currently migrating a CLI to it in order to leverage the shipped Python instance due to some jankiness in the production environments.