[译]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 ...
随机推荐
- XMind常用快捷方式汇总
快捷键(Windows) 快捷键(Mac) 描述 Ctrl+N Command+N 建立新工作簿 Ctrl+O Command+O 开启工作簿 Ctrl+S Command+S 储存目前工作簿 Ctr ...
- 自学Zabbix3.2-配置功能简介
zabbix配置功能介绍 zabbix配置内容比较多,我们要分为9大块来讲解.分别如下: 1. 主机与组 添加主机配置与组配置. 1.1.创建主机方法 1.1.1 新建主机 c ...
- 移植 MQTT broker mosquitto 到 omapl138
概述 本次移植使用创龙的 TL138-EVM 开发板,基于 TI 的 MCSDK 开发环境.具体上位机系统为 Ubuntu 12.04-32bit,软件环境基于创龙的用户手册搭建. 为了移植后在 13 ...
- C#相关知识总结
字符串相关知识 判断某字符串中包含某个字符,并过滤 if (string.Contains("*")) string = string.Replace('*',' '); // ...
- 快收藏!高手Linux运维管理必备工具大全,你会吗?
一.统一账号管理 1.LDAP 统一管理各种平台帐号和密码,包括但不限于各种操作系统(Windows.Linux),Linux系统sudo集成,系统用户分组,主机登入限制等:可与Apache,HTTP ...
- MyEclipse 2014 破解版下载:我有,需要的给我说一声,给你发过去
1.破解版的,需要的在下面给我说一声,云盘给你发过去.
- idea和Webstorm上使用git和github,码云
由于之前一直使用svn,现在项目使用git,顾根据网上找的学习资料,自己梳理了下,收获蛮多,这里做个记录,如果能帮助到您那是最好不过的. 1.大致步骤 使用工具:idea,github,码云 webs ...
- SQL Server-聚焦ROW_NUMBER VS TOP N性能
前言 抱歉各位,从八月份开始一直在着手写EntityFramework 6.x和EntityFramework Core 2.0的书籍写作,所以最近一直遗漏了对博客的管理,后面会着手于写SQL Ser ...
- iOS 本地项目上传github,github管理项目配置
一.注册github账号 首先需要注册一个github账号,注册地址:https://github.com 接着会来到这 然后会收到一封github发的邮件,进入邮箱验证 二.创建个人的githu ...
- ubuntu16.04 查询ip,网关,dns信息
用ifconfig命令只能查询ip,子网掩码信息,不能获取dns和网关信息 用下面命令即可查询 nmcli dev show