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
camellias
V2EX  ›  Python

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

  •  
  •   camellias · 2015-06-08 12:48:09 +08:00 · 2901 次点击
    这是一个创建于 3260 天前的主题,其中的信息可能已经有所发展或是发生改变。
    诡异的问题,谁能告知为何吗,搜过没看到有同种情况的
    12 条回复    2015-06-09 00:10:56 +08:00
    strongcoder
        1
    strongcoder  
       2015-06-08 12:51:30 +08:00
    进入目录侯这样执行
    python hello.py
    biaoxinxiuge
        2
    biaoxinxiuge  
       2015-06-08 13:11:29 +08:00
    行首添加#!/usr/bin/python,告诉shell使用/usr/bin/python来运行此脚本。
    henryon
        3
    henryon  
       2015-06-08 13:12:31 +08:00
    #!/bin/env python
    Andrewliu
        4
    Andrewliu  
       2015-06-08 13:21:40 +08:00
    行首添加#!/usr/bin/env python
    lilydjwg
        5
    lilydjwg  
       2015-06-08 13:29:36 +08:00
    @henryon 没听说过有系统的 env 位于 /bin 而不是 /usr/bin 呀。

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

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

    sudo alias vi="python"
    lilydjwg
        8
    lilydjwg  
       2015-06-08 14:07:03 +08:00
    @mortal alias: command not found.
    wind3110991
        9
    wind3110991  
       2015-06-08 20:58:22 +08:00
    @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  
       2015-06-08 21:07:17 +08:00
    @lilydjwg
    @wind3110991

    这么严谨=。=
    camellias
        11
    camellias  
    OP
       2015-06-08 21:42:53 +08:00
    @mortal 好吧你是对的,最终解决就是那条当日手贱添加到.zshrc中的别名
    谢各位
    phx13ye
        12
    phx13ye  
       2015-06-09 00:10:56 +08:00
    @camellias 6的飞起
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5532 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 06:59 · PVG 14:59 · LAX 23:59 · JFK 02:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.