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

mac 终端中执行 Python 脚本时如何不输入脚本所在位置的绝对路径

  •  
  •   mccast · Mar 20, 2017 · 2801 views
    This topic created in 3363 days ago, the information mentioned may be changed or developed.

    比如: python3 xxx.py 是否可以将脚本 xxx.py 放入某个目录中,执行时不需输入其绝对路径呢? 新手,谢谢各位。

    6 replies    2017-03-20 22:29:54 +08:00
    zsz
        1
    zsz  
       Mar 20, 2017 via iPhone   ❤️ 1
    1. chmod u+x 脚本加上可执行权限
    2. 脚本文件头加上如下代码

    #! /usr/bin/envy python
    # coding: utf-8
    把脚本放入系统环境变量的路径中即可

    有问题可以加我们的群问,这样效率更高,这个群是一群工程师组建的面向初学者的 python Linux 学习群, qq 群号: 278529278 ,非商业性质,拒绝广告,只接收真正想学这方面技术的朋友,交流学习,申请请说明来自 v2ex
    knightdf
        2
    knightdf  
       Mar 20, 2017   ❤️ 1
    楼上的方法,或者:
    alias command=python3 xxx/xx.py
    ynyounuo
        3
    ynyounuo  
       Mar 20, 2017 via iPhone   ❤️ 1
    一楼有 typo
    我建议楼主 Google shebang
    然后 man chmod

    然后就什么都明白了
    ynyounuo
        4
    ynyounuo  
       Mar 20, 2017 via iPhone
    奥,还有 PATH
    C0VN
        5
    C0VN  
       Mar 20, 2017   ❤️ 1
    去查查系统环境变量是干嘛用的。

    为什么你输入 ls ,就执行了 ls 命令
    试一试
    > which ls
    mccast
        6
    mccast  
    OP
       Mar 20, 2017
    谢谢各位大神,你们太友善了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5825 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 02:13 · PVG 10:13 · LAX 19:13 · JFK 22:13
    ♥ Do have faith in what you're doing.