Can I generate a python executable file on my Mac

2019-07-31 06:36发布

问题:

I am programming python with my Mac laptop, however, the final executable will be run on final users' Windows system. And the Windows system hasn't set up the python environment specifically.

Can I generate an executable file on my Mac laptop, and Windows user can directly run on Windows system?

I looked at py2exe, but it seems it must build the python on Windows in order to run the exe on Windows.

回答1:

You can not generate Windows executable files on OS X. You must use the platform which you want the program to run on to compile the program. If you own a copy of Windows, you could run a virtual machine on you Mac and compile it on that.



回答2:

If you are able to install a VM running Windows on your Mac, you will be able to create your Windows executable.

You can start from here: https://www.virtualbox.org/wiki/Downloads

So it is technically possible to create your Windows apps on your Mac but not on OSX.



回答3:

No. Every OS uses different compilers. You will need to create your executable for each target OS on that OS. Fortunately you can usually use the same tool on each OS though. For example, you can use cx_freeze on any OS to create the executable for that OS on which it is run.

PyInstaller also works on all 3 major platforms. As others have pointed out, technically you could own a Mac and install a virtual machine that has Windows on it and another virtual machine with your flavor of Linux that you can then create your executables on. Virtualbox is probably the best free utility out there for this.