(I am using ubuntu 12.04)
(我使用的是ubuntu 12.04)
I made this python program:
我制作了这个python程序:
#!/bin/sh
# -*- coding: utf-8 -*-
#Created on Tue Nov 12 19:44:50 2013
#@author: matthew
import os
print "Multiple Command Runner"
print "<Made by Matthew Cherrey>"
print "-------------------------"
numbcommand = 0
allcoms = []
while 1:
numbcommand = numbcommand + 1
command = raw_input(" Command: ")
allcoms.append(command)
decide = raw_input("Press [Enter] to and another command, press [r] to run all commands: ")
if decide == "r":
break
commands = ""
first = True
for item in allcoms:
if first:
commands = item
else:
commands = commands + " && " + item
os.system(commands)
And I want to be able to run it in the terminal. I use the python editor: Spyder This has an option to "Run in system terminal". Whenever I do this, my program works perfectly. I can enter multiple commands, and have them all run. When I set the file to an exicutible and run /home/matthew/.runallcommands.py --python
or /home/matthew/.runallcommands.py
, first makes my cursor into a "t" which then when I click somewere, is take a picture of that area of the screen and saves it as a photo named "OS" in my home folder. then I get this error message:
我希望能够在终端中运行它。我使用python编辑器:Spyder这有一个选项“Run in system terminal”。每当我这样做,我的程序运作完美。我可以输入多个命令,并让它们全部运行。当我将文件设置为exicuable并运行/home/matthew/.runallcommands.py --python或/home/matthew/.runallcommands.py时,首先将我的光标变为“t”,然后当我点击某些时,是拍摄屏幕区域的照片,并将其保存为我的主文件夹中名为“OS”的照片。然后我收到此错误消息:
matthew@matthew-MS-7721:~$ /home/matthew/.runallcommands.py --python
Warning: unknown mime-type for "Multiple Command Runner" -- using "application/octet-stream"
Error: no such file "Multiple Command Runner"
Warning: unknown mime-type for "<Made by Matthew Cherrey>" -- using "application/octet-stream"
Error: no such file "<Made by Matthew Cherrey>"
/home/matthew/.runallcommands.py: 13: /home/matthew/.runallcommands.py: numbcommand: not found
/home/matthew/.runallcommands.py: 14: /home/matthew/.runallcommands.py: allcoms: not found
/home/matthew/.runallcommands.py: 17: /home/matthew/.runallcommands.py: Syntax error: "(" unexpected (expecting "do")
I am not sure if it has something to do with how I called the file, because my program worked 100% fine in the terminal in spyder.
我不确定它是否与我调用文件的方式有关,因为我的程序在spyder终端中工作率100%。
1 个解决方案
#1
1
The first line instructs the system to run this with the Bourne shell, not with the Python interpreter.
第一行指示系统使用Bourne shell运行它,而不是使用Python解释器。
Change
更改
#!/bin/sh
to something like
喜欢的东西
#!/usr/bin/env python
When you run it from your Python IDE, the IDE knows it is a Python script, so it explicitly invokes the Python interpreter, bypassing the instruction on the first line.
当您从Python IDE运行它时,IDE知道它是一个Python脚本,因此它显式调用Python解释器,绕过第一行的指令。
See also Shebang on Wikipedia
另见*上的Shebang
#1
1
The first line instructs the system to run this with the Bourne shell, not with the Python interpreter.
第一行指示系统使用Bourne shell运行它,而不是使用Python解释器。
Change
更改
#!/bin/sh
to something like
喜欢的东西
#!/usr/bin/env python
When you run it from your Python IDE, the IDE knows it is a Python script, so it explicitly invokes the Python interpreter, bypassing the instruction on the first line.
当您从Python IDE运行它时,IDE知道它是一个Python脚本,因此它显式调用Python解释器,绕过第一行的指令。
See also Shebang on Wikipedia
另见*上的Shebang