1

On a server I am working on, I need to run the following commands to ensure the xlsxwriter is available to import from python:

module load swdev
module load python/xlsxwriter_py3.4.2/0.7.2

However, I would like this to be done automatically when the python script that needs it is run, from within the python script. Running os.system or subprocess.call doesn't work. How do I do this?

texasflood
  • 1,571
  • 1
  • 13
  • 22

1 Answers1

0

You can call module from a Python script. The module command is provided by the environment-modules software, which also provides a python.py initialization script.

Evaluating this script in a Python script enables the module python function. If environment-modules is installed in /usr/share/Modules, you can find this script at /usr/share/Modules/init/python.py.

Following code enables module python function:

import os
exec(open('/usr/share/Modules/init/python.py').read())

Thereafter you can load your modules:

module('load', 'swdev')
module('load', 'python/xlsxwriter_py3.4.2/0.7.2')