2016-11-07 109 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 /斌/包膜蟒蛇