If you have several versions of Python installed, /usr/bin/env will ensure the interpreter used is the first one on your environment's $PATH. The alternative would be to hardcode something like #!/usr/bin/python; that's ok, but less flexible. In Unix, an executable file that's meant to be interpreted can indicate what interpreter to use by having a #! at the start of the first line, followed by the interpreter (and any flags it may need). If you're talking about other platforms, of course, this rule does not apply (but that "shebang line" does no harm, and will help if you ever copy that script to a platform with a Unix base, such as Linux, Mac, etc).

如果你的电脑安装了多个版本的Python,/usr/bin/env将会确保解释器第一个是你环境的$PATH,替代的方法使用像#!/usr/bin/python硬编码的方式也可以,只是不太灵活。

在Unix系统中,在第一行用#!后面跟随解释器符号,来表明一个可是文件简要被什么解释器解释执行。

如果你的话说的是其他平台的话,当然这些规则并不适用,(但是"shebang行"并没有坏处,而且如果你将此脚本拷贝到类Unix的系统(Linux,Mac等)时会非常有帮助。)

[译]Why do people write #!/usr/bin/env python on the first line of a Python script?的更多相关文章

  1. #!/usr/bin/env python与#!/usr/bin/python的区别

    [摘自:http://blog.csdn.net/wh_19910525/article/details/8040494] 一般的python文件的开头都有#!/usr/bin/python.这是什么 ...

  2. Cannot install NodeJs: /usr/bin/env: node: No such file or directory

    安装doxmate时,doxmate地址是:https://github.com/JacksonTian/doxmatenpm install doxmate -g 安装完后把错误:Cannot in ...

  3. 配置webstorm使用supervisor时出现 /usr/bin/env: node: 没有那个文件或目录 解决方法

    配置好supervisor路径后 出现了 启动时出现了 /usr/bin/env: node: 没有那个文件或目录 需要讲.nvm下的node链接到, /usr/bin/目录下 sudo ln -s ...

  4. /usr/bin/env: node: no such file or directory

    今天在安装gulp的之后,运行gulp命令出现了如下报错: /usr/bin/env: node: no such file or directory 网上找了好久,终于解决了,所以记录一下,便于下次 ...

  5. Python 头部 #!/usr/bin/python 和 #!/usr/bin/env 的区别

    这个网址 https://www.cnblogs.com/scofi/p/4867851.html 讲述了Python 头部 #!/usr/bin/python 和 #!/usr/bin/env 的区 ...

  6. 安装composer时,提示 /usr/bin/env: php: 没有那个文件或目录

    今晚在Ubuntu环境上安装composer后,想查看下是否安装成功,使用composer -v,结果提示:/usr/bin/env: php: 没有那个文件或目录 现说说我的解决办法: 它提示的原因 ...

  7. #!/usr/bin/python3 和 #!/usr/bin/env python3的区别

    脚本语言的第一行指出用什么程序去执行代码. #!/usr/bin/python3调用/usr/bin下的python3解释器.#!/usr/bin/env python3首先会到env设置里查找pyt ...

  8. !/usr/bin/env python和!/usr/bin/python的区别

    脚本语言第一行 作用:文件中代码用指定可执行程序运行 #!/usr/bin/Python  执行脚本时,调用/usr/bin下python解释器 #!/usr/bin/env python  在环境设 ...

  9. python中#!/usr/bin/env python与#!/usr/bin/python

    通常在脚本语言的第一行会看到#!/usr/bin/env python 与 #!/usr/bin/python其中之一,这两句话的目的都是指出你的python文件用什么可执行程序去运行它. #!/us ...

随机推荐

  1. PHP对象注入 PHP Object Injection

    From:PHP Object Injection Last revision (mm/dd/yy): 01/7/2015 译者:李秋豪 Wednesday, 24. May 2017 05:48PM ...

  2. springboot 项目maven 打包错误

    Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.5.6.RELEASE:repackage ...

  3. gradle发布jar包

    在.gradle文件中添加以下代码 apply plugin: 'application' mainClassName = 'com.excel.ExcelApplication' jar { doF ...

  4. .net 裁剪图片(不压缩)

    命名空间: using System.Drawing; using System.Drawing.Imaging; /// <summary> /// 生成图片缩略文件 /// </ ...

  5. .net 图片无损压缩

    命名空间: using System.Drawing.Imaging; using System.Drawing; using System.Drawing.Drawing2D; #region Ge ...

  6. .NET 实现Base-64加密解密处理

    .NET 实现Base-64加密解密处理 using System; using System.Collections.Generic; using System.Linq; using System ...

  7. 4.python迭代器生成器装饰器

    容器(container) 容器是一种把多个元素组织在一起的数据结构,容器中的元素可以逐个地迭代获取,可以用in, not in关键字判断元素是否包含在容器中.通常这类数据结构把所有的元素存储在内存中 ...

  8. python每天进步一点点

    1. apply, 可以调用函数和参数,如apply(Fun,(xxx,xxx)) 2. Format, 很好处理字符串的对齐命名,其他进制,打印等. 3. input(),接受输入 4. str() ...

  9. 【JMeter】JMeter代码里若有外部自定义方法调用需要写进方法体里,否则报错

  10. 4.前端基于react,后端基于.net core2.0的开发之路(4) 前端打包,编译,路由,模型,服务

    1.简要的介绍 学习react,首先学习的就是javascript,然后ES6,接着是jsx,通常来说如果有javascript的基础,上手非常快,但是真正要搭建一个前端工程化项目,还是有很多坑的 搞 ...