简体   繁体   English

为什么我的python脚本不能作为Mac应用程序运行?

[英]Why doesn't my python script run as a Mac app?

I've written a little GUI with tkinter for my own purposes on my Mac. 我已经在Mac上为自己的目的使用tkinter编写了一个GUI。 I've written a two-line bash script to run it, and I can launch it from my desktop by double-clicking an icon. 我已经编写了一个两行的bash脚本来运行它,并且可以通过双击图标从桌面启动它。 This is fine, but it pops up a terminal window, which I find annoying. 很好,但是会弹出一个终端窗口,我觉得很烦。

I would like to have it run as an app, without opening a terminal window. 我想让它作为应用程序运行,而无需打开终端窗口。 I followed the instructions in ccpizza's answer to create an app with Automator. 我按照ccpizza答案中的说明使用Automator创建应用。 I chose /usr/bin/python as the shell, and pasted in my python code. 我选择/usr/bin/python作为外壳,并粘贴到我的python代码中。 When I click on the desktop icon, I get an error box that says, 当我点击桌面图标时,我看到一个错误框,

The action “Run Shell Script" encountered an error.  

The console log has the error, 控制台日志中有错误,

LaunchServices: Could not store lsd-identifiers file at /private/var/db/lsd/com.apple.lsdschemes.plist

I saw that /private/var/db/lsd is owned by root and I am the owner of the app. 我看到/private/var/db/lsd由root拥有,并且我是该应用程序的所有者。 I tried 我试过了

sudo chown root <appname>

and it doesn't give an error, but I am still shown as the owner of the app. 并且没有给出错误,但我仍然显示为该应用的所有者。

I've also tried choosing usr/local/bin/bash as the shell script, pasting in my bash script. 我还尝试选择usr/local/bin/bash作为shell脚本,并粘贴到我的bash脚本中。 When I run click the icon, I don't even get an error box, but the same error shows up in the console log. 运行时,单击图标,我什至没有看到错误框,但控制台日志中会显示相同的错误。

Is there an easy fix for this? 有一个简单的解决办法吗? I'm just interested in getting this method to work. 我只是想让这种方法起作用。 I'd rather not do anything more elaborate, like installing py2app or platypus. 我宁愿不做任何更复杂的事情,例如安装py2app或platypus。

I ended up getting platypus. 我最终得了鸭嘴兽。 It was trivial to do what I wanted. 做我想做的事是微不足道的。 Just pick "None" for the interface. 只需为界面选择“无”。

如果您只想编写python脚本并作为应用程序运行,则可以尝试pyinstaller

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM