我只想把我的脚本作为一个应用程序。双击并运行,而不是在终端中运行。我以前用过自动机,但现在,在埃尔卡皮坦,它不起作用。它只会给出错误而没有解释。
当我尝试使用automator时,会出现以下错误:
"The action “Run Shell Script” encountered an error."
我也试过下面的把戏,还是做不到。
#!/usr/bin/env python
chmod +x script.py
SOLVED:
After these two steps. I changed "Open with" to terminal for only this file and changed the
#!/usr/bin/env python
, it works. But it doesn't work without the two steps below, you need to follow all steps.在代码开头添加
#!/usr/local/bin/python
。那就跑吧chmod +x myscript.py
在终端。之后更改应用程序 打开到终端。这对我有效。
快速逐步创建clickable.app以启动您的python脚本。
启动Apple ScriptEditor(位于/Applications/Utilities/)并在编辑器中键入以下内容:
之后,只需点击save并选择另存为应用程序。
注:如果有人读到这篇文章,知道如何摆脱你启动.app时打开的终端窗口,请告诉我。
如果您想更高级,请查看Platypus。
假设安装了Python,这应该可以工作:
附录:
附录2:
苹果在ElCapitan做了一些改变(包括System Integrity Protection),这可能会导致安装失败,因为臭名昭著的“找不到可安装的软件”。例如:
解决方法:
使用自制。这正是我上面引用的Installing Python on Mac OS X所建议的:
如果这对你不起作用,请告诉我。
我改变了模式
sudo chmod +x file-name.py
然后在文件名.py的顶部添加以下行
#!/usr/bin/env python
然后通过运行
./file-name.py
命令运行该文件,它可以正常工作。相关问题 更多 >
编程相关推荐