如何在Windows上使用Python创建OS X应用 [英] How to create OS X app with Python on Windows

查看:138
本文介绍了如何在Windows上使用Python创建OS X应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要自动化跨平台应用程序构建.整个构建都在Windows计算机上运行.一部分是用Python编写的,并且可以在OS X上编译.目前,这部分构建是在OS X上手动完成的.

I need to automate a cross-platform application build. Entire build runs on Windows machine. Part of it is written in Python and compiles for OS X. Currently this part of build is done manually on OS X.

我尝试了pyinstaller,但看起来它只是为正在运行的平台构建的.我还尝试了py2app,但未在Windows上安装.

I tried pyinstaller but it looks like it only building for the platform that it is running on. I also tried py2app but it did not install on Windows.

有没有工具可以将Python脚本编译到Windows计算机上的OS X应用程序中?

Are there any tools to compile Python script to OS X app on Windows machine?

推荐答案

简短答案:

很显然,没有简单的方法可以使用您提到的标准工具集来做到这一点.最后,我概述了一个完全不可能的解决方案,它可能太复杂了,无法考虑.

Short answer:

Apparently, no simple way to do this with the standard set of tools you have mentioned. I outline a completely unprobable solution in the end that's probably too complex to consider.

最终结果: 继续手动进行,到目前为止,这可能是最好的选择.

End result: Keep doing it manually, it's probably the best option so far.

micheal0x2a的 中,< 从Python项目创建单个可执行文件 ,其中概述了可用于创建Python独立发行版的大多数工具程序.一行突出:

There's already a long and curated list of options specified in micheal0x2a's excelent answer in Create a single executable from a Python project which outlines most tools available for creating standalone distributions of a Python program. One line stands out:

此外,除非另有说明,否则 下面列出的所有程序都会为其运行的操作系统专门生成一个exe.

Also, unless otherwise noted, all programs listed below will produce an exe specifically for the operating system it's running in.

我可能看错了东西,但是没有明确说明跨平台支持.

I might have read things wrong but there's no explicit note of cross platform support.

类似的列表可以在 Distribution Utilities 冻结代码-《 Python旅行者指南》 .从这些我们可以看一下Windows支持的项目:

Similar lists can be found in in Distribution Utilities and Freezing Your Code — The Hitchhiker's Guide to Python. From these we can take a look at the Windows supported projects:

bbfreeze :未维护,没有文档限制通常会被此列表中的其他限制所取代.

bbfreeze: Not maintained, no documentation on limitations generally superceded by the rest in this list.

PyInstaller :根据他们的

PyInstaller已针对Windows,Mac OS X和Linux进行了测试. 但是,它不是交叉编译器:要制作Windows应用程序,请在Windows中运行PyInstaller.要制作可在Linux等系统上运行的Linux应用. PyInstaller已成功与AIX,Solaris和FreeBSD结合使用,但尚未针对它们进行测试.

PyInstaller is tested against Windows, Mac OS X, and Linux. However, it is not a cross-compiler: to make a Windows app you run PyInstaller in Windows; to make a Linux app you run it in Linux, etc. PyInstaller has been used successfully with AIX, Solaris, and FreeBSD, but is not tested against them.

PyInstaller曾经尝试支持交叉编译(从Linux-> Windows),但是 后来放弃了这个想法 .

PyInstaller once tried to support cross-compilation (From Linux -> Windows) but later dropped the idea.

cx_freeze :查看他们的 冻结其他平台的问题 常见问题 列表:

cx_freeze: Looking at their Freezing for other platforms question in their Frequently Asked Questions list:

cx_Freeze可在Windows,Mac和Linux上运行,但是 在每个平台上它只能生成一个在该平台上运行的可执行文件.因此,如果要冻结Windows程序,请在Windows上冻结它.如果要在Mac上运行,请在Mac上将其冻结.

cx_Freeze works on Windows, Mac and Linux, but on each platform it only makes an executable that runs on that platform. So if you want to freeze your program for Windows, freeze it on Windows; if you want to run it on Macs, freeze it on a Mac.


py2app :由于仅受基于OSX机器的注释的支持:


py2app: This is not an option since py2app is supported only OSX machines based on their note:

注意:必须在OSX上使用py2app来构建应用程序, 它不能在其他平台上创建Mac应用程序 .

NOTE: py2app must be used on OSX to build applications, it cannot create Mac applications on other platforms.

所以不能在Windows上安装它.

So installing it on windows is a no-go.

这总结了可用于在Windows上创建独立应用程序的工具.即使不是在Windows上,创建操作系统不可知工具的解决方案也不存在.

This wraps out the tools available on for creating standalone applications on Windows. Even if not on Windows though, solutions don't exist for creating an OS agnostic tool.

达成这类目标的普遍共识是通过虚拟机;您创建目标OS的VM映像,在vm中运行该OS的专用工具,然后将捆绑的可执行文件传输到兼容计算机.由于OSX通常不容易虚拟化,据我所知,您在这里有点运气不足.

The general consensus for achieving these sort of things is via Virtual Machines; you create a VM image of the target OS, run the dedicated tool for that OS inside the vm and then tranfer the bundled executable to compatible machines. Since OSX is generally not easy to virtualize, from what I know, you kinda run out of luck here.

现在,我之所以说没有简单的方法来执行此操作,是因为可能会有一个,但是据我所见,它是如此乏味,您甚至不应该考虑它.我们在这里面临的一般问题是Windows的可执行文件根本不兼容OSX,例如,

Now, the reason why I said there is no simple way to do this is because there might be one but, from what I can see, it is so tedious you shouldn't even consider it. The general issue we're facing here is that executables for windows are simply not compatible with OSX, heck, Linux executables aren't either. So what we need is the ability to cross-compile things.

我听说过的一个编译器 支持交叉编译 clang .因此,为了纠正可执行文件的不兼容性,从理论上讲,您可以将clang用作交叉编译器.问题是,这不是简单的任务;由于

One compiler that I've heard supports cross-compilation is clang. So, in order remedy the incompatibility of executables, you could theoretically use clang as a cross compiler. Problem is, this is not a simple task; it is probably way harder than what you're willing to do since it is riddled with complex issues (From OSX to Windows example).

如果您确实找到了解决之道,则现在需要使用python脚本中的.cpp/.c文件.幸运的是,可以使用 Nuitka 之类的工具来完成此操作 Cython .

If you do actually find a way to that you now need a .cpp/.c file from your python scripts. Thankfully this is something that can be done by using tools like Nuitka or Cython.

这些要旨相同,输入.py退出.cpp/.c.第二个棘手的部分可能是设置要与它们一起使用的clang编译器.老实说,我不知道是否有人这样做.

The gist of these is the same, enter .py exit .cpp/.c. The second tricky part might be setting up the clang compiler to be used with these. I honestly have no idea if anyone has done this.

我没有研究太多,但是对于Nuitka,我知道它也可以用于创建

I haven't looked into them much, but for Nuitka, I know that it can also be used to create a standalone executable when passed the --standalone flag (See: Moving to other machines). So, theoretically you could use Nuitka with clang configured to cross-compile for OSX. Then you can rest; you've earned it.

这篇关于如何在Windows上使用Python创建OS X应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆