2016-11-07 90 views
0

我在Ubuntu中运行一个依赖于正在安装的软件包的python脚本。这些都安装,因为我可以调用它们,但脚本不能。在Ubuntu中执行python脚本默认为shell而不是bash

我想这是因为该脚本使用shell(SH),而不是在bash version.i收到此错误信息进行:

sh: genomeCoverageBed: command not found 

,但可以在猛砸手动调用genomeCoverageBed:

[email protected]:~/jonathan/scripty$ genomeCoverageBed 


Tool: bedtools genomecov (aka genomeCoverageBed) 
Version: v2.26.0 

Summary: Compute the coverage of a feature file among a genome. 

我的问题#1这部分是误导和错误的!:

我加入这个家当的明星!我的python脚本的T:不过这并没有影响结果

#/斌/庆典

考虑了这一点,我的剧本还是引起了同样的错误消息 下面是部分脚本:

for filename in os.listdir(folder): 
if filename.endswith(".sorted.bam"): 
    namefile = filename.replace(".sorted.bam", "_ncoverage.txt") 
    folder_name = filename.replace(".sorted.bam", "") 
    os.system("mkdir " + folder_name) 
    os.system("coverageBed -s -d -a bam " + folder + filename + " -b " + gff_file + " > " + folder_name + "/" + namefile) 

这里是当我运行此脚本会发生什么:

[email protected]:~/jonathan/script$ sudo python2.7 script1.py ./Folder/ ./Folder/ref.fasta genbank.gff 
sh: coverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: coverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: coverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: coverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: coverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: coverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: coverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: coverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: coverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 
sh: genomeCoverageBed: command not found 

对于我能做什么,或者即使我走上正轨,你有什么建议吗? 感谢您的帮助!

+0

恩,你把'#!/ bin/sh'放在python脚本的顶部?它运行一个子shell,而不是python。 – tdelaney

+0

确切地说,你的脚本是用什么语言编写的,'python'或'bash'? – jojo

+0

这个脚本是用python –

回答

0

你的shebang正在调用一个子shell,就像@tdelaney在评论中提到的那样。您需要使用像下面这样使用Python作为程序执行文件:

#! /usr/bin/env python 
2

您使用了错误的家当

#!/bin/bash 

当一个Linux shell被要求运行一个文本文件(例如./myprogram.py),它看着shebang找出应该用哪个程序来解释文本。在你的情况下,你要求shell运行/bin/bash - 另一个shell,它试图将python脚本解释为shell脚本。

你可以写的家当不同

#!/usr/bin/env python3 

这告诉运行/usr/bin/env这将搜索的路径,一个叫pythnon3事情外壳。现在,您为当前环境运行python安装程序。默认情况下它的系统是python,但是如果你运行在python虚拟环境中,它运行 python。

shebang仅在linuxy系统上使用,仅在您使脚本可执行并直接运行时才会使用。如果在windows(cygwin或其他类Unix外壳之外)上运行或直接运行python(python /path/to/myscript.py),则不使用它。

+0

为了确认,我试图在bash环境中演示python脚本,是吗?我通常运行脚本如下:sudo python2.7 script.py –

+0

你最后的评论对我来说是最重要的。你只能使用shebang来使脚本可执行并直接运行它。我误导了你和其他人,包括我的错误快速修复'#!/ bin/bash'。原来的问题仍然存在 –

+1

@JonathanAbrahams你可以发布你的失败的python脚本的一个小例子吗?只要把它解释成几行来展示问题,并在你的问题中加上一个完整的堆栈跟踪(如果适用)。然后我们可以解决这个问题。 – tdelaney

0

如果您将#!/ bin/bash打开,将会在bash中打开,Ubuntu将不会运行python中的python文件。试着把#!/ usr/bin/python或#!在/ usr /斌/包膜蟒蛇