繁体   English   中英

Python程序将在Spyder终端中运行,但不能在常规的Linux终端中运行

[英]Python program will run in Spyder terminal, but not in a regular linux terminal

(我正在使用ubuntu 12.04)

我做了这个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)

我希望能够在终端中运行它。 我使用python编辑器: Spyder这具有“在系统终端中运行”的选项。 每当我这样做时,我的程序就可以完美运行。 我可以输入多个命令,然后全部运行。 当我将文件设置为可使用并运行/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")

我不确定它是否与我如何调用文件有关,因为我的程序在spyder的终端中可以100%正常工作。

第一行指示系统使用Bourne shell(而不是Python解释器)运行此代码。

更改

#!/bin/sh

#!/usr/bin/env python

当从Python IDE运行它时,IDE知道它是一个Python脚本,因此它显式调用Python解释器,从而绕开了第一行的指令。

另请参阅Wikipedia上的Shebang

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM