[译]Why do people write #!/usr/bin/env python on the first line of a Python script?
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?的更多相关文章
- #!/usr/bin/env python与#!/usr/bin/python的区别
[摘自:http://blog.csdn.net/wh_19910525/article/details/8040494] 一般的python文件的开头都有#!/usr/bin/python.这是什么 ...
- Cannot install NodeJs: /usr/bin/env: node: No such file or directory
安装doxmate时,doxmate地址是:https://github.com/JacksonTian/doxmatenpm install doxmate -g 安装完后把错误:Cannot in ...
- 配置webstorm使用supervisor时出现 /usr/bin/env: node: 没有那个文件或目录 解决方法
配置好supervisor路径后 出现了 启动时出现了 /usr/bin/env: node: 没有那个文件或目录 需要讲.nvm下的node链接到, /usr/bin/目录下 sudo ln -s ...
- /usr/bin/env: node: no such file or directory
今天在安装gulp的之后,运行gulp命令出现了如下报错: /usr/bin/env: node: no such file or directory 网上找了好久,终于解决了,所以记录一下,便于下次 ...
- Python 头部 #!/usr/bin/python 和 #!/usr/bin/env 的区别
这个网址 https://www.cnblogs.com/scofi/p/4867851.html 讲述了Python 头部 #!/usr/bin/python 和 #!/usr/bin/env 的区 ...
- 安装composer时,提示 /usr/bin/env: php: 没有那个文件或目录
今晚在Ubuntu环境上安装composer后,想查看下是否安装成功,使用composer -v,结果提示:/usr/bin/env: php: 没有那个文件或目录 现说说我的解决办法: 它提示的原因 ...
- #!/usr/bin/python3 和 #!/usr/bin/env python3的区别
脚本语言的第一行指出用什么程序去执行代码. #!/usr/bin/python3调用/usr/bin下的python3解释器.#!/usr/bin/env python3首先会到env设置里查找pyt ...
- !/usr/bin/env python和!/usr/bin/python的区别
脚本语言第一行 作用:文件中代码用指定可执行程序运行 #!/usr/bin/Python 执行脚本时,调用/usr/bin下python解释器 #!/usr/bin/env python 在环境设 ...
- python中#!/usr/bin/env python与#!/usr/bin/python
通常在脚本语言的第一行会看到#!/usr/bin/env python 与 #!/usr/bin/python其中之一,这两句话的目的都是指出你的python文件用什么可执行程序去运行它. #!/us ...
随机推荐
- java中md5加密方法
package com.func; import java.io.UnsupportedEncodingException;import java.math.BigInteger;import jav ...
- 【java】控制台实现贪吃蛇小游戏-LinkedList、Scanner
package com.myproj.snake; public class Node { private int i,j; public Node(){} public Node(int i, in ...
- 【python】函数说明文档
- C#中MessageBox用法大全(转)
我们在程序中经常会用到MessageBox. MessageBox.Show()共有21中重载方法.现将其常见用法总结如下: 1.MessageBox.Show("Hello~~~~&quo ...
- InnoDB 逻辑存储结构
本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/80 如果创建表时没有显示的定义主键,mysql会按如下方式创建主 ...
- Hello TensorFlow 三 (Golang)
在一台ubuntu 16.04.2虚拟机上为golang安装TensorFlow. 官方参考:https://www.tensorflow.org/install/install_go 首先安装go ...
- Oracle学习笔记_08_字符串连接
附录:参考资料 1.Oracle中字符串连接的实现方法 2.SQL指令— CONCAT(字符串连接函数)
- prototype为对象添加属性和方法
可以通过prototype来为已经定义好的的"类"添加属性和方法.这里来了解一下prototype的基础知识.prototype是"构造函数"的属性,不是实例的 ...
- 视频流GPU解码在ffempg的实现(二)-GPU解码器
1.gpu解码器的基本调用流程 要做视频流解码,必须要了解cuda自身的解码流,因为二者是一样的底层实现,不一样的上层调用 那cuda的解码流程是如何的呢 在https://developer.nvi ...
- 吓尿了,mac下bash出了问题
由于个人的脑残行为,使用homebrew安装bash后,使用chsh命令将其改成brew安装的特定版本的bash,结果上次brew更新bash之后,就彻底用不了shell了... 无奈只能添加新的管理 ...