2

I'm trying to get a script running. Essentially I need to load some modules and then execute a python script. So something like this...

#!/usr/bin/env bash
module use /PATH/TO/MODULEFILE
module load MY_MODULE

python my_script.py

The problem that I get is that every time I try to execute the script I get this error - "module: command not found". I don't understand how to change the script to fix this. I am able to run the module command from the shell. I also ran "whereis -b module" and I just got "module:".

What do I need to do to get this module loaded from inside the script? Thanks

user3047641
  • 149
  • 1
  • 2
  • 12
  • 2
    Load the modules inside the the python script `my_script.py`, not inside the bash script. PS: You don't need the bash script if you put `#! /usr/bin/python` at the top of you python script. – Socowi Oct 24 '17 at 19:21

2 Answers2

0

You can enable the module command from your python script by sourcing the python.py initialization script provided in the init directory of the Modules installation.

Following piece of python code defines module function, then enables a modulepath and load a modulefile:

#!/usr/bin/python
import os
exec(open('/PATH/TO/MODULES/init/python.py').read())
module('use', '/PATH/TO/MODULEFILE')
module('load', 'MY_MODULE')
0

If you want to enable the module within your bash script, it could be as simple as using a different command to run the script. For me, running a script script.sh as . script.sh or as ./script.sh will correctly load the module, but running it as sh script.sh will lead to the error you described above.

Christian Seitz
  • 728
  • 6
  • 15