Writing python on mac to use on Windows

Question:

I’ve seen from some sources that although you can make an exe or mac equivalent app using py2exe or py2app, you can only make the one your system is. Makes sense when I think about it.

But my problem is sometimes I want to write python scripts and send them to my Windows-using friends to test and play with. But Windows doesn’t come with python installed, and I don’t want to make them have to install Python.

Is there any way to use a MAC to create a python-made file that can be opened without python or any installation ON WINDOWS?

If there’s not I suppose I could try using the emulated Windows on my system to make it an exe, but I’d rather not boot that every time I need to change something.

Asked By: user1159454

||

Answers:

You can’t make a native py2exe-style executable on Mac. Use Virtualbox to run Windows inside your Mac environment. No need to reboot the whole machine.

Answered By: Ned Batchelder

Depending on how many dependencies you’re willing to install on your machine (your friends with Windows shouldn’t have any installation to do), another alternative would be to use IronPython. It won’t compile all python code, but it works for a very large subset of it.

And the resulting .exe files can be run on your Mac using the Mono runtime, and on your friend’s Windows system using the very likely already installed .NET runtime.

Here’s what you would need to do:

  1. Install the Mono runtime.
  2. Install IronPython 2.7.2 or later.
  3. Run mono ipy.exe pyc.py /main:your_program.py /target:exe /embed
  4. This will produce a .exe file that can be run on Windows, Mac, and Linux. On your Mac, you’d do mono your_program.exe. On Windows, your friends can just double-click the .exe file if they have .NET 4.0 installed (very good chance that they do).
Answered By: sblom
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.