在python脚本中加载环境模块 [英] Loading environment modules within a python script

查看:181
本文介绍了在python脚本中加载环境模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以让python脚本加载和使用环境模块 os.system('module load xxx')不能工作,因为它在subshel​​l中执行它们(至少我认为这是发生了什么)。

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 least, I think that's what's happening).

推荐答案

我知道这个问题很旧,但它仍然足够相关,我正在寻找答案,所以我发布我发现的工作还有:

I know this question's kind of old but it's still relevant enough that I was looking for the answer, so I'm posting what I found that works as well:

至少在3.2.9+的源代码中,可以包含pythoninit文件以获取模块的python函数版本:

At least in the 3.2.9+ sources, you can include the python "init" file to get a python function version of module:

>>> execfile('/usr/local/Modules/default/init/python.py')
>>> module('list')
No Modulefiles Currently Loaded.
>>> module('load','foo')
>>> module('list')
Currently Loaded Modulefiles:
  1) foo/1.0

我已经被告知早期版本可以做同样的没有.py扩展名,但这是二手,所以ymmv。

I've been told earlier versions can do the same without the .py extension, but that's second hand, so ymmv.

这篇关于在python脚本中加载环境模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆