module load command in linux bash script

skwang picture skwang · Jul 20, 2017 · Viewed 24.1k times · Source

I need to execute Python script in HPC cluster. Unfortunately, the default python version is just 2.6.6 and there is no numpy and scipy.

I can load these modules in command line

#module load /home/hw1u16/modules/2.7.3

and

module load /home/hw1u16/modules/1.6.2

However, when I write the bash script like this

module load /home/hw1u16/modules/2.7.3
module load /home/hw1u16/modules/1.6.2
python /home/hw1u16/project/trainAgent.py

It warns me

ModuleCmd_Load.c(200):ERROR:105: Unable to locate a modulefile for '/home/hw1u16/modules' ModuleCmd_Load.c(200):ERROR:105: Unable to locate a modulefile for '/home/hw1u16/modules' I don't know what's wrong, could any guys help me?

Answer

Christian Seitz picture Christian Seitz · Dec 5, 2019

I had a similar problem, and found two solutions:

  1. instead of running your script with sh yourscript.sh or ./yourscript.sh, you could run it as . yourscript.sh This will source the module correctly and run the script

  2. if you don't want to use . yourscript.sh, you can modify your shebang from #!/bin/sh to #!/bin/bash as noted in DavidC's answer and run your script as ./yourscript.sh Note that running it as sh yourscript.sh will not work