Loading environment modules within a python script

后端 未结 4 1382
一个人的身影
一个人的身影 2020-12-05 07:13

Is there a way for a python script to load and use environment modules? os.system(\'module load xxx\') doesn\'t work since it executes them in a subshell (at le

4条回答
  •  -上瘾入骨i
    2020-12-05 08:03

    While the accepted solution works, I found it to be easier to write:

    import sys
    sys.path.insert(0, '/path/to/environment/modules')
    # Environment modules become available by loading python.py (the name choice could be better here)
    import python as mod
    
    # ...
    mod.module('use', '/some/dir')
    mod.module('load', 'program/1.2.3')
    

    This looks more pythonic to me and also it allows IDEs to offer auto-completion etc.

提交回复
热议问题