【发布时间】:2020-08-10 23:28:30
【问题描述】:
我使用的是 MacBook Pro 16"(使用 MacOS Catalina)。我想通过 Spotlight 搜索直接运行 Python 脚本。我不想打开任何 IDE 或终端。我已经看到说明我要:
-
编写并保存我的 Python 代码,例如:print("Hello World"),在主文件夹 Users/Gory 中保存为 hello.py
-
使用 TextEdit 创建一个文本文件并将其保存为 .command 文件扩展名(例如:samplescript.command)。该文件应包含以下内容
#!/usr/bin/env bash python3 /Users/Gory/hello.py -
通过在终端中运行,使上面创建的 shell 脚本(samplescript.command)可执行:
chmod u+x samplescript.command
完成上述步骤后,我通过 Spotlight 搜索 samplescript.command 并按下回车键。我希望在终端窗口上看到“Hello World”。相反,我收到以下消息:
MacBook-Pro:~ Gory$ /Users/Gory/samplescript.command ; exit;
/Users/Gory/samplescript.command: line 1: {rtf1ansiansicpg1252cocoartf2511: command not found
/Users/Gory/samplescript.command: line 2: syntax error near unexpected token `}'
/Users/Gory/samplescript.command: line 2: `\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}'
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]
怎么了?
【问题讨论】: