终端打开 py 文件显示 permission denied

2018 年 4 月 2 日
 lukeshawn
新人刚入门 python.
py 文件是用 sublime text 保存的
终端打开后显示下面这个
-bash: /Users/shawn/Documents/PYTHON/hello.py: Permission denied

另求解 sublime text 如何运行代码
6852 次点击
所在节点    Python
12 条回复
jmc891205
2018 年 4 月 2 日
> python /Users/shawn/Documents/PYTHON/hello.py

or

> chmod u+x /Users/shawn/Documents/PYTHON/hello.py
> /Users/shawn/Documents/PYTHON/hello.py
willxiang
2018 年 4 月 2 日
lukeshawn
2018 年 4 月 2 日
@jmc891205 你好,我在命令行模式下输入了你的 2 种方法,方法一没变,方法二显示:-bash: u+x: command not found ;
然后我试着在 python 交互模式下输入这个,显示 SyntaxError: invalid syntax
araraloren
2018 年 4 月 2 日
Maybe your python script missing the executable permission.
lukeshawn
2018 年 4 月 2 日
@araraloren how to figure it out
yxy2829
2018 年 4 月 2 日
加 sudo
mssora
2018 年 4 月 2 日
@lukeshawn #1 的命令都是在 shell 里面运行的,还有如果要直接运行需要在脚本第一行指定解释器:#!/usr/bin/env python
mcfog
2018 年 4 月 2 日
@lukeshawn 大于号是用来表示这是一行 bash 指令,并不需要实际输入在 bash 当中
rammiah
2018 年 4 月 2 日
新人先用 IDE 吧,一键运行,还有提示。
lukeshawn
2018 年 4 月 2 日
@mcfog 成功了,谢谢。
lukeshawn
2018 年 4 月 2 日
@yianing sublime 无法一键运行的么
rammiah
2018 年 4 月 2 日
@lukeshawn #11 懒得配那些插件,

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/443590

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX