我有一个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
答案 0 :(得分:0)
如果没有看到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脚本会很有帮助。