最近用Python写了一些脚本,Python本地运行代码没问题。运用Py2app库打包出来MacOS的程序启动会报错LaunchError。
打包步骤
- 运行pip3 install -U py2app
- 将自己的代码脚本放到一个目录下,进到该目录运行 python setup.py install
- 运行py2applet --make-setup Main.py
- 运行python setup.py py2app -A ,打出的包启动报错LaunchError;清掉build、dist等构建出来的目录,重新运行python setup.py py2app,打出的包启动报错LaunchError。 这里加-A 会指示 py2app 构建一个应用程序包,该包就地使用您的源文件和数据文件。不加 “应用程序是独立的,因此每次py2app 更改任何源代码、数据文件、选项等时都必须再次运行该命令。”
Terminal调试报错日志
默认 lsd Non-fatal error enumerating at <private>, continuing: Error Domain=NSCocoaErrorDomain Code=260 "未能打开文件“PlugIns”,因为它不存在。" UserInfo={NSURL=PlugIns/ -- file:///Users/xxxxx/xxxxx.app/Contents/, ...., NSUnderlyingError=0x7f973044b690 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
默认 loginwindow -[PersistentAppsSupport applicationReady:] | App: BatchInstaller, ready, updating active tracking timer
默认 oginwindow -[ApplicationManager checkInAppContext:refCon:eventData:] | checked in app : .....
默认 distnoted register name: com.apple.sharedfilelist.change object: com.apple.LSSharedFileList.ApplicationRecentDocuments/org.pythonmac.unspecified.batch
环境
- Python 3.7
- Py2app 26.1
- MacOS系统:在MacOS10.1和M1上都试了,都会启动报错,报错日志一样
Py2app官网:https://py2app.readthedocs.io/en/latest/tutorial.html#clean-up-your-build-directories