I need to submit a python job to a server. While it is running I need to load and unload modules while it runs since it calls several programs, each with different dependencies that conflict i.e. gcc versus intel.
This question has been asked before but the answers have not worked for me in this situation
Loading environment modules within a python script
loading-environment-modules-within-a-python-script
I have tried using the following
import subprocess as sub
cmd = 'module load intel/2016.4'
p = sub.Popen(cmd, shell=True, stderr = sub.STDOUT, stdout = sub.PIPE).communicate()[0]
print(p.decode()) # this simply outputs to screen
And, the output says that modules have been switched.
Lmod is automatically replacing "gcc/5.4.0" with "intel/2016.4".
Due to MODULEPATH changes, the following have been reloaded:
1) openmpi/2.1.1
However, when I do 'module list' from the terminal, the modules have not been switched. gcc/5.4.0
is still loaded. Also the program requiring intel/2016.4
fails to run. For instance later I want to be able to use a version of gromacs that requires intel/2016.4
and it fails.
I am a little confused since I thought I was able to use bash commands via Popen and 'module load' is a bash command. I don't want to have to write a bash script to do this, there is alot of other things in my script done much more conveniently with python than bash.