如何使用 py2app?
好的 - 开始了。我想学习如何使用 py2app,所以我创建了一个简单的 python 文件;只是 hello_world.py
#! /usr/bin/env python
def main():
print "Hello"
if __name__=="__main__":
main()
我按照教程执行了以下操作:
py2applet --make-setup hello.py
python setup.py py2app -A
这创建了两个子目录(build 和 dist),在 dist 中有一个名为 hello.app 的文件。我尝试通过 GUI 启动它,但它启动了不到一秒钟,然后就消失了。然后我去了 CL,但只是尝试运行它不起作用,所以我使用了:
python hello.app
出现以下错误:
/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python: can't find '__main__.py' in 'hello.app'
我花了一整天的时间进行谷歌搜索,但找不到任何教程或指南等。我真的陷入了困境:- (
我不知道这是否有帮助,但这就是 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'],
)
Ok - here goes. I am trying to learn how to use py2app, so I created a simple python file; just 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:
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
"""
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'],
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您已成功使用 py2app - 它只是打开,打印“hello”,然后很快关闭!
如果您想查看某些内容,请让它暂停一下:
time.sleep将程序暂停给定的秒数。
You have successfully used py2app - it just opens, prints "hello" and then closes really quickly!
If you want to see something, then make it pause for a bit:
time.sleep pauses a program for the number of seconds given.
您实际上只想将 py2app 与 GUI 应用程序或在后台运行的应用程序一起使用。
如果您想从命令行运行 py2app 构建的应用程序,则需要执行应用程序包内的二进制文件;捆绑包本身不能直接执行,所以像这样:
对于仅打印到标准输出的脚本,您可以尝试 Platypus (尽管它不做 py2app 的依赖打包工作)。
You really only want to use py2app with GUI apps, or ones that run in the background.
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:
For scripts that just print to stdout you might try Platypus (though it doesn't do the dependency-packaging stuff of py2app).
看起来它一直在起作用——脚本运行得太快了,我没有机会看到它。如果有人遇到此问题,请访问 http://svn.pythonmac.org/ py2app/py2app/trunk/doc/index.html 并按照教程进行操作。另请阅读我给出的答案和留下的回复。
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.html and follow the tutorial. Please also read the answers given and the replies I left.