推荐学习书目
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
camellias
V2EX  ›  Python

比如 Mac 下给以权限,终端下执行./hello.py 时,无法执行,总是 vi 打开 hello.py

  •  
  •   camellias · Jun 8, 2015 · 3778 views
    This topic created in 4027 days ago, the information mentioned may be changed or developed.
    诡异的问题,谁能告知为何吗,搜过没看到有同种情况的
    12 replies    2015-06-09 00:10:56 +08:00
    strongcoder
        1
    strongcoder  
       Jun 8, 2015
    进入目录侯这样执行
    python hello.py
    biaoxinxiuge
        2
    biaoxinxiuge  
       Jun 8, 2015
    行首添加#!/usr/bin/python,告诉shell使用/usr/bin/python来运行此脚本。
    henryon
        3
    henryon  
       Jun 8, 2015
    #!/bin/env python
    Andrewliu
        4
    Andrewliu  
       Jun 8, 2015
    行首添加#!/usr/bin/env python
    lilydjwg
        5
    lilydjwg  
       Jun 8, 2015
    @henryon 没听说过有系统的 env 位于 /bin 而不是 /usr/bin 呀。

    你的描述非常不清楚。我需要以下信息:

    1. 你的文件有没有 shebang(第一行是不是 #! 开头),以及它是什么
    2. 你的文件有没有可执行权限
    3. 你的 shell 是什么,是不是设置了对不可执行文件,按文件后缀启动相应的程序?
    Andy1999
        6
    Andy1999  
       Jun 8, 2015 via iPhone
    python xxx.py ……
    mortal
        7
    mortal  
       Jun 8, 2015
    我来恶搞一下……

    sudo alias vi="python"
    lilydjwg
        8
    lilydjwg  
       Jun 8, 2015
    @mortal alias: command not found.
    wind3110991
        9
    wind3110991  
       Jun 8, 2015
    @mortal
    第一,MacOS没有自带alias,所以不可能执行alias命令引用
    第二,你的情况可能是没有进入正确目录,如果你用终端的话,要不直接打

    """
    python (把执行文件拖到终端自动生成文件路径)
    """

    如果不行就是python bash下启动项环境错误了
    """
    vim .bash_profile
    """
    看下,里面的环境PATH正确没有,是不是你之前配置vim的时候乱加了东西进去
    python 2.7应该是这样的

    """ python 2.7
    # Setting PATH for Python 2.7
    # The orginal version is saved in .bash_profile.pysave
    PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
    export PATH
    """

    """python 3.4
    # Setting PATH for Python 3.4
    # The orginal version is saved in .bash_profile.pysave
    PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
    export PATH
    """
    mortal
        10
    mortal  
       Jun 8, 2015
    @lilydjwg
    @wind3110991

    这么严谨=。=
    camellias
        11
    camellias  
    OP
       Jun 8, 2015
    @mortal 好吧你是对的,最终解决就是那条当日手贱添加到.zshrc中的别名
    谢各位
    phx13ye
        12
    phx13ye  
       Jun 9, 2015
    @camellias 6的飞起
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3758 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 105ms · UTC 04:19 · PVG 12:19 · LAX 21:19 · JFK 00:19
    ♥ Do have faith in what you're doing.