macos 我如何使用 py2app?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5607121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how do I use py2app?
提问by Grahame Thomson
Ok - here goes. I am trying to learn how to use py2app, so I created a simple python file; just hello_world.py
好的 - 来了。我正在尝试学习如何使用 py2app,所以我创建了一个简单的 python 文件;只是 hello_world.py
#! /usr/bin/env python
def main():
print "Hello"
if __name__=="__main__":
main()
I followed a tutorial and did the following:
我按照教程进行了以下操作:
py2applet --make-setup hello.py
python setup.py py2app -A
This created two sub-directories (build and dist), within dist there was a file called hello.app. I attempted to launch it through the GUI but it launched for less than a second and then disappeared. I then went to the CL but simply trying to run it didn't work so I used:
这创建了两个子目录(build 和 dist),在 dist 中有一个名为 hello.app 的文件。我试图通过 GUI 启动它,但它启动不到一秒钟,然后消失了。然后我去了 CL,但只是尝试运行它没有用,所以我使用了:
python hello.app
with the following error:
出现以下错误:
/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python: can't find '__main__.py' in 'hello.app'
I've spent all day googling but can't find any tutorials or guides etc. I'm really stuck :-(
我花了一整天的时间在谷歌上搜索,但找不到任何教程或指南等。我真的被困住了 :-(
I don't know if this helps but this is what is in the setup.py
我不知道这是否有帮助,但这是 setup.py 中的内容
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['hello.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
回答by James
You have successfully used py2app - it just opens, prints "hello" and then closes really quickly!
您已成功使用 py2app - 它只是打开,打印“你好”,然后很快就关闭了!
If you want to see something, then make it pause for a bit:
如果你想看一些东西,那就让它暂停一下:
print "Hello"
import time
time.sleep(5)
time.sleeppauses a program for the number of seconds given.
time.sleep暂停程序给定的秒数。
回答by Nicholas Riley
You really only want to use py2app with GUI apps, or ones that run in the background.
您真的只想将 py2app 与 GUI 应用程序或在后台运行的应用程序一起使用。
If you want to run the py2app-built application from the command line, you need to execute the binary inside the application bundle; the bundle itself is not directly executable, so something like this:
如果要从命令行运行 py2app 构建的应用程序,则需要执行应用程序包内的二进制文件;捆绑包本身不能直接执行,所以是这样的:
dist/hello.app/Contents/MacOS/hello
For scripts that just print to stdout you might try Platypus(though it doesn't do the dependency-packaging stuff of py2app).
对于只打印到标准输出的脚本,您可以尝试Platypus(尽管它不执行 py2app 的依赖项打包)。
回答by Grahame Thomson
It seems that it was working all along - the script was just running so quickly I didn't have a chance to see it. If anyone comes across this go to http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.htmland follow the tutorial. Please also read the answers given and the replies I left.
似乎它一直在工作 - 脚本运行得太快了,我没有机会看到它。如果有人遇到这个问题,请访问http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html并按照教程进行操作。另请阅读给出的答案和我留下的回复。