gpt4 book ai didi

python - Lion 上的 py2app 正在创建没有 python 框架或资源的空应用程序

转载 作者:太空宇宙 更新时间:2023-11-03 12:09:59 25 4
gpt4 key购买 nike

我有一个 python 脚本,在升级到 Lion 之前我已经成功地用 py2app 打包了它。

现在,当我运行 py2app 时,它没有错误地完成,但是生成的 .app 只有 216K,并且在执行时它提示缺少 objc(这是脚本中的第一个导入)。

py2app 输出:

running py2app
creating /Users/byron/Dropbox/dev/Hours-Worked/build
creating /Users/byron/Dropbox/dev/Hours-Worked/build/bdist.macosx-10.7-intel
creating /Users/byron/Dropbox/dev/Hours-Worked/build/bdist.macosx-10.7-intel/python2.7-semi_standalone
creating /Users/byron/Dropbox/dev/Hours-Worked/build/bdist.macosx-10.7-intel/python2.7-semi_standalone/app
creating /Users/byron/Dropbox/dev/Hours-Worked/build/bdist.macosx-10.7-intel/python2.7-semi_standalone/app/collect
creating /Users/byron/Dropbox/dev/Hours-Worked/build/bdist.macosx-10.7-intel/python2.7-semi_standalone/app/temp
creating /Users/byron/Dropbox/dev/Hours-Worked/dist
creating build/bdist.macosx-10.7-intel/python2.7-semi_standalone/app/lib-dynload
creating build/bdist.macosx-10.7-intel/python2.7-semi_standalone/app/Frameworks
*** using recipe: virtualenv ***
*** filtering dependencies ***
376 total
372 filtered
0 orphaned
4 remaining
*** create binaries ***
*** byte compile python files ***
byte-compiling /Library/Python/2.7/site-packages/py2app-0.6.3-py2.7.egg/py2app/bootstrap/boot_app.py to boot_app.pyc
byte-compiling /Library/Python/2.7/site-packages/py2app-0.6.3-py2.7.egg/py2app/bootstrap/chdir_resource.py to chdir_resource.pyc
byte-compiling /Library/Python/2.7/site-packages/py2app-0.6.3-py2.7.egg/py2app/bootstrap/disable_linecache.py to disable_linecache.pyc
byte-compiling /Users/byron/Dropbox/dev/Hours-Worked/hours-worked.py to hours-worked.pyc
*** creating application bundle: Hours-Worked ***
copying hours-worked.py -> /Users/byron/Dropbox/dev/Hours-Worked/dist/Hours-Worked.app/Contents/Resources
creating /Users/byron/Dropbox/dev/Hours-Worked/dist/Hours-Worked.app/Contents/Resources/lib
creating /Users/byron/Dropbox/dev/Hours-Worked/dist/Hours-Worked.app/Contents/Resources/lib/python2.7
copying build/bdist.macosx-10.7-intel/python2.7-semi_standalone/app/site-packages.zip -> /Users/byron/Dropbox/dev/Hours-Worked/dist/Hours-Worked.app/Contents/Resources/lib/python2.7
creating /Users/byron/Dropbox/dev/Hours-Worked/dist/Hours-Worked.app/Contents/Resources/lib/python2.7/lib-dynload
creating /Users/byron/Dropbox/dev/Hours-Worked/dist/Hours-Worked.app/Contents/Frameworks
stripping Hours-Worked
stripping saved 15936 bytes (71424 / 87360)

运行应用程序:

$ ./dist/Hours-Worked.app/Contents/MacOS/Hours-Worked 
Traceback (most recent call last):
File "/Users/byron/Dropbox/dev/Hours-Worked/dist/Hours-Worked.app/Contents/Resources/__boot__.py", line 31, in <module>
_run('hours-worked.py')
File "/Users/byron/Dropbox/dev/Hours-Worked/dist/Hours-Worked.app/Contents/Resources/__boot__.py", line 28, in _run
execfile(path, globals(), globals())
File "/Users/byron/Dropbox/dev/Hours-Worked/dist/Hours-Worked.app/Contents/Resources/hours-worked.py", line 3, in <module>
import objc
ImportError: No module named objc
2011-08-09 15:27:40.306 Hours-Worked[16825:707] Hours-Worked Error

生成的应用程序如下所示:

$ du -hs dist/Hours-Worked.app/Contents/*
0B dist/Hours-Worked.app/Contents/Frameworks
4.0K dist/Hours-Worked.app/Contents/Info.plist
76K dist/Hours-Worked.app/Contents/MacOS
4.0K dist/Hours-Worked.app/Contents/PkgInfo
132K dist/Hours-Worked.app/Contents/Resources

它曾经看起来像:

$ du -hs Hours-Worked.app/Contents/*
4.0M Hours-Worked.app/Contents/Frameworks
4.0K Hours-Worked.app/Contents/Info.plist
188K Hours-Worked.app/Contents/MacOS
4.0K Hours-Worked.app/Contents/PkgInfo
12M Hours-Worked.app/Contents/Resources

最佳答案

没有看到您的 setup.py 文件,我最好的猜测是您没有明确包含 PyObjC 库。例如

from setuptools import setup

OPTIONS = {'argv_emulation': False,
'includes': ['objc'],
}
setup(
app='myapp.app',
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)

将强制 py2app 包含 objc 库。如果您已经这样做,那么查看您的 setup.py 脚本会很有帮助。

关于python - Lion 上的 py2app 正在创建没有 python 框架或资源的空应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6992929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com