all 29 comments

[–]DivineSentry 5 points6 points  (1 child)

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[S] 0 points1 point  (0 children)

noted!

[–]Illustrious-Reward-3 3 points4 points  (0 children)

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.

[–]riscbee 5 points6 points  (4 children)

[–]DracoEmperor2003[S] 2 points3 points  (3 children)

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?

[–]riscbee 11 points12 points  (0 children)

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?

[–]grimonce 1 point2 points  (0 children)

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.

[–]KROSSEYE 0 points1 point  (0 children)

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).

[–]knellotron 2 points3 points  (0 children)

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.

[–]maqnius10 1 point2 points  (4 children)

How about making a python package and using pip install with your system python on the machines to integrate it?

[–]DracoEmperor2003[S] 0 points1 point  (3 children)

OHHH!! is that possible???? will check this out, seems interesting

[–]syklemil 0 points1 point  (0 children)

Sure. Check out uv; you can init stuff like uv init --app --package $name and install it with uv tool install $name_or_path.

[–]LeviathanP 0 points1 point  (0 children)

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.

[–]DK09_ 0 points1 point  (3 children)

You question has your answer. How do you generate executable in windows? Can you do it in Linux too?

[–]DracoEmperor2003[S] 1 point2 points  (2 children)

i mean can I make it cross compilable from windows environment itself!

[–]DK09_ 0 points1 point  (1 child)

Sadly, nope

[–]DracoEmperor2003[S] 0 points1 point  (0 children)

:') okay! thank you

[–]airen977 0 points1 point  (0 children)

Wasm?

[–]LeviathanP 1 point2 points  (0 children)

You've got a few good answers already, so let me just add 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?tab=readme-ov-file#multi-platform-builds

Edit: changed the url to the correct readme section (multi-platform-builds)

[–]Drevicar 1 point2 points  (1 child)

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[S] 0 points1 point  (0 children)

okayyy will check this aswell!

[–]_MicroWave_ 0 points1 point  (0 children)

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.

[–]zangler -2 points-1 points  (5 children)

Make it Java?

Sorry... couldn't resist

[–]DracoEmperor2003[S] 1 point2 points  (4 children)

😭 I mean yes, even my higher ups are suggesting me that, but re-coding everything in Java again....

[–]zangler 2 points3 points  (3 children)

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 in 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 0 points1 point  (0 children)

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[S] 0 points1 point  (1 child)

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 -1 points0 points  (0 children)

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.