如何使用Python创建Mac OS X应用程序? [英] How to create a Mac OS X app with Python?

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

问题描述

我想创建一个可以在Windows和Mac上运行的GUI应用程序.为此,我选择了Python.

I want to create a GUI application which should work on Windows and Mac. For this I've chosen Python.

问题出在Mac OS X上.

The problem is on Mac OS X.

有两种工具可以为Mac生成".app":py2app和pyinstaller.

  1. py2app相当不错,但是它在包中添加了源代码.一世 不想与最终用户共享代码.
  2. Pyinstaller生成UNIX可执行文件,那么如何在Mac上运行它?一世 使用此可执行文件创建了一个包,但结果为".app"为 不起作用.
  1. py2app is pretty good, but it adds the source code in the package. I don't want to share the code with the final users.
  2. Pyinstaller generates UNIX executable, so how to run it on Mac? I created a bundles with this executable, but the resulted ".app" is not working.

问题是:

  1. 如何配置py2app以将源代码包含在 可执行文件,这样最终用户将无法访问我的程序?
  2. 如何将UNIX可执行文件转换为Mac".app"?
  3. 是否可以使用GCC编译Python代码?
  4. 在Windows中,这很容易,我用Python代码创建了一个"exe"文件, 有用.是否可以为Mac创建单个文件"app"?
  1. How to configure py2app to include the source code in the executable, so the final users will not have access to my program?
  2. How to convert UNIX executable to Mac ".app" ?
  3. Is there a way to compile Python code with GCC ?
  4. In Windows it's easy, I created an "exe" file from Python code and it works. Is it possible to create a single file "app" for Mac ?

P.S.我使用两台计算机(Windows和Mac版),Python 2.7,wxPython,py2exe,py2app和pyinstaller.

P.S. I use two computers (Windows and for Mac), Python 2.7, wxPython, py2exe, py2app and pyinstaller.

我还检查了以下站点:

  • http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html
  • http://www.pyinstaller.org/export/develop/project/doc/Manual.html?format=raw
  • http://www.pyinstaller.org/wiki/Features/MacOsCompatibility
  • http://www.stackoverflow.com/questions/2933/an-executable-python-app

推荐答案

如何配置py2app在可执行文件中包含源代码, 这样最终用户将无法访问我的程序?

How to configure py2app to include the source code in the executable, so the final users will not have access to my program?

除非您非常认真地破解python解释器(并包括损坏的版本),否则没有真正好方法可以将源代码隐藏给具有中等技能和坚定决心的用户.我坚信在Windows上也是如此.基本上,无论您包含真实的源代码还是字节码,都可以恢复源代码的纯净版本.在我看来,更重要的是,除非您包括实际的源代码(与字节码相对,否则将引入对解释器版本的可能依赖).

Unless you very seriously hack the python interpreter (and include the mangled version) there is no really good way to hide the source from a moderately skilled and determined user. I strongly believe this is true on Windows also. Basically, whether you include true source or bytecode, a pretty clean version of the source can be recovered. More importantly, in my opinion, unless you include the actual source code (as opposed to bytecode, you will introduce a possible dependency on the interpreter version).

如何将UNIX可执行文件转换为Mac".app"?

How to convert UNIX executable to Mac ".app" ?

UNIX可执行文件是什么意思?达尔文(OS X)二进制文件[实际上不是UNIX]?可以使用您已经提到的各种工具来完成此操作,但必须谨慎进行,以避免库依赖性.

What do you mean by a UNIX executable? A Darwin (OS X) binary [which isn't actually UNIX]? That can be done using the kinds of tools you already mentioned, but it must be done carefully to avoid library dependencies.

如果只需要一个简单的包装程序就可以将命令行二进制文件放入窗口中,那么就很容易完成,免费的XCode套件提供了几个示例(取决于输出内容) 您希望提供(如果有的话).

If all you want it a simple wrapper to put a command-line binary into a window, it's pretty easy to accomplish and the free XCode suite has several examples that would serve (depending on what output you wan to deliver, if any).

是否可以使用GCC编译Python代码?

Is there a way to compile Python code with GCC ?

GCC无法编译Python.这是另一种语言(尽管gcc系列r中有支持多种语言前端的工具,但不支持Python).有一些工具尝试将Python转换为C,然后可以将其编译为真正的二进制文件,但这仅适用于避免某些构造类型的程序,并且该过程(和限制)也需要应用您的库.
Cython是一个允许这样做的项目.它对某些类型效果很好 代码,主要是数字代码,但安装和安装并非易事 利用,特别是如果您想产生可以在多个平台上运行的东西 不同的计算机.

GCC does not compile Python. It's a different language (although there tools in the gcc family rthat support multiple language front-ends, but not Python). There are tools that attempt to translate Python into C, and then you can compile that into a true binary, but this only works for programs that avoid certain types of construct, and the process (and restrictions) need to apply your libraries as well.
One project to allow this is Cython. It works well for some types of code, mostly numerical code, but it is not trivial to install and exploit, very especially if you want to produce something that runs on multiple different computers.

在Windows中,这很容易,我用Python代码创建了一个"exe"文件, 作品.是否可以为Mac创建单个文件"app"?

In Windows it's easy, I created an "exe" file from Python code and it works. Is it possible to create a single file "app" for Mac ?

我不得不说我对此表示怀疑-非常怀疑.就像OS X的情况一样,该exe几乎肯定可以在其中轻松地访问源代码.

I would have to say I am skeptical -- very skeptical -- about this. Just like the OS X case, the exe almost certainly has the source code trivially accessible within it.

一个相当简单的技巧是对源代码进行加密,然后即时对其进行解密,但这 在我看来,麻烦多于其应有的价值.

One fairly easy trick is to encrypt the source code and then decrypt it on the fly, but this seems to me like more trouble than it's worth.

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

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