linux后台执行./run.py提示python syntax error near unexpected token `('
python脚本中的#!/usr/bin/python
#!/usr/bin/python
它是用来干嘛的?貌似没有它对脚本功能也没啥影响。它是用来指定用什么解释器运行脚本以及解释器所在的位置。
以test.py为例,脚本内容如下:
def test():
print 'hello, world'
if __name__ == "__main__":
test()
运行脚本:
python test.py
输出:
hello, world
换一种方法运行:
./test.py
会提示出错,文件无可执行权限:
-bash: ./test.py: Permission denied
将文件设为可执行:
chmod +x test.py
继续运行:
./test.py
提示:
./test.py: line 1: syntax error near unexpected token `('
./test.py: line 1: `def test():'
那是因为系统默认该脚本是shell脚本,把它当shell语句执行,当然失败了。
在前面加上
#!/usr/bin/python
申明l这是个python脚本,要用python解释器来运行:
./test.py
输出:
hello, world
这个东东常用在cgi脚本中,apache启动cgi脚本时就靠它来知道这是个python脚本,执行它需要的python解释器路径在哪里。
有时候写 #!/usr/bin/python
还是不行,很简单,因为python解释器没有装在/usr/bin/目录,改成其所在目录就行了,或者更通用的方法是:
#!/usr/bin/env python
linux后台执行./run.py提示python syntax error near unexpected token `('的更多相关文章
- 执行shell脚本提示“syntax error near unexpected token for((i=0;i<$length;i++))”
sh脚本例如以下: #!/usr/bin/env bash county="3 4 5 6 7 8 9 10 11 12 16 29 39 44 53 62 72 84 97 115 128 ...
- Linux中syntax error near unexpected token 错误提示解决方法
Linux中syntax error near unexpected token ... 错误提示有一般有两种原因: 1)window和Linux下换行符不一致导致 window下的换行和Linux下 ...
- Linux 中出现的-bash: syntax error near unexpected token `
版权声明:本文为博主原创文章,未经博主允许不得转载. 在Linux 5中导入数据时,出现下面的错误. -bash: syntax error near unexpected token `(' 检查了 ...
- 解决执行脚本报syntax error: unexpected end of file或syntax error near unexpected token `fi'错误的问题
参考:https://blog.csdn.net/u012453843/article/details/69803244 解决执行脚本报syntax error: unexpected end of ...
- Shell脚本报错--syntax error near unexpected token for((i=0;i<$length;i++))
现象: shell脚本使用Nodepad++进行本地编辑,在编辑后上传到linux机器进行执行时提示“syntax error near unexpected token for((i=0;i< ...
- Linix登录报"/etc/profile: line 11: syntax error near unexpected token `$'{\r''"
同事反馈他在一测试服务器(CentOS Linux release 7.2.1511)上修改了/etc/profile文件后,使用source命令不能生效,让我帮忙看看,结果使用SecureCRT一登 ...
- syntax error near unexpected token `do(写的shell脚本出现格式问题)--->1.问题2.展示信息3.解决方案
1问题:Linux和windows下的回车换行符不兼容的问题 [root@node-01 script]# sh start_zk.sh art_zk.sh: line 3: syntax error ...
- -bash: /etc/profile: line 11: syntax error near unexpected token `$'{\r''报错问题解决
在Linux系统配置Java环境变量之后执行 source /etc/profile指令报:-bash: /etc/profile: line 11: syntax error near unexpe ...
- 关于报错“syntax error near unexpected token `”和回车换行
本来是很简单一个事情,转过来是因为打字机这事比较有趣…… http://blog.csdn.net/xyp84/archive/2009/08/11/4435899.aspx 摘要一下: 回车 换行 ...
随机推荐
- JAVA中获取键盘输入的方法总结
Java程序开发过程中,需要从键盘获取输入值是常有的事,但Java它偏偏就没有像c语言给我们提供的scanf(),C++给我们提供的cin()获取键盘输入值的现成函数!下面介绍三种解决方法: 方法一: ...
- [MySQL]group by 与 if 的统计技巧
group by查询旨在把某字段中相同的记录合并成一列,查询结果可受count(),sum()等统计函数影响 如下表 id totalclick validclick 1 3 1 2 3 1 3 5 ...
- linux强制将数据写入磁盘,防止丢失内存的数据
sync命令文件系统管理 sync命令用于强制被改变的内容立刻写入磁盘,更新超块信息. 在Linux/Unix系统中,在文件或数据处理过程中一般先放到内存缓冲区中,等到适当的时候再写入磁盘, 以提高系 ...
- CentOS7.5从零安装Python3.6.6
ps:环境如标题 安装可能需要的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlit ...
- 计算机信息类ComputerInfo(车)
using System; using System.Management; using System.Net; using System.Net.Sockets; using System.Text ...
- Android组件化demo实现以及遇坑分享
首先贴出demo的github地址:GitHub - TenzLiu/TenzModuleDemo: android组件化demo 作者:TenzLiu原文链接:https://www.jianshu ...
- 第四周学习总结-HTML
2018年8月5日 这是暑假第四周,这一周我在菜鸟教程网学到了许多HTML的知识.HTML编写网页不像C语言.Java语言那必须有主方法.主函数什么的,它基本上都是标签(元素),但是它可以与CSS(层 ...
- 官方版sublime Text3汉化和激活注册码
转载:https://www.cnblogs.com/chaonuanxi/p/9371837.html sublimeText3 很不错,前面几天下了vscore学习Node.js,感觉有点懵,今天 ...
- C语言实现split以某个字符分割一个字符串
方式一: 使用strtok # include <string.h> # include <stdio.h> void split(char *src,const char * ...
- 在lnmp环境下,将原来的PHP7.0升级到PHP7.2
基础环境: 系统:centos6.8 环境:lnmp 停止PHP7.0的版本,在做如下操作: 1.下载php-7.2.6.tar.bz2软件包放在/opt 路径下 mkdir /usr/local ...