简体   繁体   English

linux bash脚本中的模块加载命令

[英]module load command in linux bash script

I need to execute Python script in HPC cluster.我需要在 HPC 集群中执行 Python 脚本。 Unfortunately, the default python version is just 2.6.6 and there is no numpy and scipy.不幸的是,默认的 python 版本只有 2.6.6,没有 numpy 和 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但是,当我像这样编写 bash 脚本时

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? 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 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而不是使用sh yourscript.sh./yourscript.sh运行您的脚本,您可以将其作为. yourscript.sh . yourscript.sh This will source the module correctly and run the script . yourscript.sh这将正确获取模块并运行脚本

  2. if you don't want to use . yourscript.sh如果您不想使用. yourscript.sh . 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 . yourscript.sh ,您可以将您的shebang从#!/bin/sh#!/bin/bash如DavidC的回答中所述,并将您的脚本作为./yourscript.sh运行请注意,将其作为sh yourscript.sh运行将不起作用

Okay, I think I know where is the problem.好的,我想我知道问题出在哪里了。 Try type module from the shell to see how module it is currently defined in your system.尝试type module从外壳看怎么module它是在你的系统当前定义。 You will receive two options: either it is an alias or a function.您将收到两个选项:别名或函数。 This is because the module command is an alias or shell function .这是因为module命令是aliasshell function

Say your script is the following running.sh :假设您的脚本如下running.sh

#!/bin/bash  
module load python/2.7.3
python /home/hw1u16/project/trainAgent.py

(It is a good practice to add the shebang) (添加shebang是一个很好的做法)

To sort out this problem you have two options:要解决此问题,您有两种选择:

  • Option 1:选项 1:

source the scitpt. source scitpt。 In other words, do: source running.sh .换句话说,做: source running.sh This is exactly the same as typing the module command directly into your interactive shell.这与直接在交互式 shell 中键入module命令完全相同。 However, by doing ./running.sh , you are running a new, non-interactive shell.但是,通过执行./running.sh ,您正在运行一个新的非交互式 shell。 These generally do not have the standard aliases and shell functions set up.这些通常没有设置标准别名和 shell 函数。

  • Option 2:选项 2:

Find the initialization script that defines the module command and source it from the script查找初始化脚本定义module的命令和source从脚本它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM