我在 Ubuntu 中运行一个 python 脚本,它依赖于正在安装的包。这些都已安装,因为我可以调用它们,但脚本不能。
我认为这是因为脚本使用的是 shell(sh) 而不是 bash 版本。我得到了这条错误消息:
sh: genomeCoverageBed: command not found
但可以在 Bash 中手动调用 genomeCoverageBed:
ubuntu@fat:~/jonathan/scripty$ genomeCoverageBed
Tool: bedtools genomecov (aka genomeCoverageBed)
Version: v2.26.0
Summary: Compute the coverage of a feature file among a genome.
我的 Stackoverflow 问题的这一部分具有误导性和错误性!
I have added this shebang to the start of my python script:
#!/bin/bash
But this has not affected the outcome,
从我的脚本中删除它仍然会导致相同的错误消息 这是脚本的一部分:
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)
以下是我运行此脚本时发生的情况:
ubuntu@fat:~/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
您对我能做什么有什么建议,或者即使我走在正确的轨道上? 感谢您的帮助!
最佳答案
你用错了 shebang
#!/bin/bash
当 linux shell 被要求运行一个文本文件时(例如,./myprogram.py
),它会查看 shebang 以确定应该使用哪个程序来解释文本。在您的情况下,您要求 shell 运行 /bin/bash
- 另一个 shell,它试图将 python 脚本解释为 shell 脚本。
你可以用不同的方式写 shebang
#!/usr/bin/env python3
这会告诉 shell 运行 /usr/bin/env
,它将在 PATH 中搜索名为 python3
的东西。现在,您为当前环境运行 python 安装程序。默认情况下它是系统 python,但如果您在 python 虚拟环境中运行,它会运行 that python。
shebang 仅在 linuxy 系统上使用,并且仅在您使脚本可执行并直接运行时使用。如果在 Windows 上运行(在 cygwin 或其他类似 unix 的 shell 之外)或直接运行 python (python/path/to/myscript.py
),那么它不会被使用。
关于python - 在 Ubuntu 中执行 python 脚本默认为 shell 而不是 bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40468490/