简体   繁体   English

在python中,使用os.system调用模块,然后基于该模块调用python模块

[英]In python, calling a module using os.system, then calling a python module based on that

I am currently writing a python script. 我目前正在编写python脚本。

The ultimate goal here is just to import pysam. 这里的最终目标只是导入pysam。 But, to do this, first I import a suite of tools known as galaxy, of which pysam is one. 但是,为此,我首先导入了一套称为星系的工具,其中pysam是其中之一。

If on the command line I first load galaxy, then enter the python interactive shell, then import pysam, the import is successful. 如果我在命令行上先加载银河,然后输入python交互式外壳,然后导入pysam,则导入成功。

But, my script is like so: 但是,我的脚本是这样的:

#!/usr/bin/env python

import subprocess

subprocess.call("module load galaxy/galaxy", shell=True)
subprocess.call("module load ngs-ccts/tabix/0.2.6", shell=True)
import pysam

caddfile=pysam.Tabixfile( "/scratch/share/public_datasets/ngs/databases/CADD/v1.0/whole_genome_SNVs_inclAnno.tsv.gz" )
for gtf in caddfile.fetch(1, 100000, 200000):
    print(gtf)

to me, this seems to recapitulate what I do in the interactive shell, which works. 对我而言,这似乎概括了我在交互式外壳程序中所做的工作,该程序有效。

The script, however, errors and returns: 但是,该脚本会出错并返回:

Traceback (most recent call last):
  File "pysampracticer.py", line 7, in ?
    import pysam
ImportError: No module named pysam

why is it that the script fails to import it while the same series of commands will work on the command line then the python interactive shell, and how should I approach this to recapitulate the results obtained on the interactive shell? 为什么脚本无法导入它,而在命令行上然后是python交互式shell才能在命令行上使用相同系列的命令,我该如何概括在交互式shell上获得的结果呢?

subprocess.call("module load galaxy/galaxy", shell=True)
subprocess.call("module load ngs-ccts/tabix/0.2.6", shell=True)

Loads the modules in sub-processes. 在子流程中加载模块。 It doesn't affect the current process. 它不会影响当前的过程。

Not only that, the two calls create two independent sub-processes. 不仅如此,这两个调用还创建了两个独立的子流程。 In the first sub-process, the galaxy/galaxy module is loaded but not the ngs-ccts/tabix/0.2.6 modue. 在第一个子过程中,将加载galaxy/galaxy模块,但不会加载ngs-ccts/tabix/0.2.6 In the second sub-process, the ngs-ccts/tabix/0.2.6 is loaded but not the galaxy/galaxy module. 在第二个子过程中, ngs-ccts/tabix/0.2.6 ,但不加载galaxy/galaxy模块。

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

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