V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
lukeshawn
V2EX  ›  Python

终端打开 py 文件显示 permission denied

  •  
  •   lukeshawn · 2018-04-02 16:17:43 +08:00 · 5900 次点击
    这是一个创建于 2188 天前的主题,其中的信息可能已经有所发展或是发生改变。
    新人刚入门 python.
    py 文件是用 sublime text 保存的
    终端打开后显示下面这个
    -bash: /Users/shawn/Documents/PYTHON/hello.py: Permission denied

    另求解 sublime text 如何运行代码
    12 条回复    2018-04-02 18:39:19 +08:00
    jmc891205
        1
    jmc891205  
       2018-04-02 16:19:54 +08:00
    > python /Users/shawn/Documents/PYTHON/hello.py

    or

    > chmod u+x /Users/shawn/Documents/PYTHON/hello.py
    > /Users/shawn/Documents/PYTHON/hello.py
    lukeshawn
        3
    lukeshawn  
    OP
       2018-04-02 16:38:38 +08:00
    @jmc891205 你好,我在命令行模式下输入了你的 2 种方法,方法一没变,方法二显示:-bash: u+x: command not found ;
    然后我试着在 python 交互模式下输入这个,显示 SyntaxError: invalid syntax
    araraloren
        4
    araraloren  
       2018-04-02 16:46:48 +08:00
    Maybe your python script missing the executable permission.
    lukeshawn
        5
    lukeshawn  
    OP
       2018-04-02 16:54:31 +08:00
    @araraloren how to figure it out
    yxy2829
        6
    yxy2829  
       2018-04-02 17:10:55 +08:00
    加 sudo
    mssora
        7
    mssora  
       2018-04-02 17:35:24 +08:00
    @lukeshawn #1 的命令都是在 shell 里面运行的,还有如果要直接运行需要在脚本第一行指定解释器:#!/usr/bin/env python
    mcfog
        8
    mcfog  
       2018-04-02 18:17:07 +08:00
    @lukeshawn 大于号是用来表示这是一行 bash 指令,并不需要实际输入在 bash 当中
    yianing
        9
    yianing  
       2018-04-02 18:34:50 +08:00
    新人先用 IDE 吧,一键运行,还有提示。
    lukeshawn
        10
    lukeshawn  
    OP
       2018-04-02 18:37:44 +08:00
    @mcfog 成功了,谢谢。
    lukeshawn
        11
    lukeshawn  
    OP
       2018-04-02 18:38:40 +08:00
    @yianing sublime 无法一键运行的么
    yianing
        12
    yianing  
       2018-04-02 18:39:19 +08:00
    @lukeshawn #11 懒得配那些插件,
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2692 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 15:11 · PVG 23:11 · LAX 08:11 · JFK 11:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.