dmmpie
dmmpie

Reputation: 445

How can I call aliases that modify my current shell environment from within a python script?

I would like to load a module from within a python script. I am using a custom manager called spack which has a spack load <module> functionality that is similar to the regular module load command on linux. I have tried using both os and subprocessing to run these commands, but the result is always that nothing happens, even though I do not get an error message.

Issuing

spack load mpi

makes the module appear in the list resulting from

spack find --loaded

However, calling these commands in python causes nothing to happen at all:

out = os.popen('spack load mpi').read()
out, err = subprocess.Popen(['spack load mpi'], stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
out, err = subprocess.Popen(['spack', 'load', 'mpi'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)

Is there something else I can try? Why does this command only work when I type it directly into my shell session? How can I make this load command apply to the particular shell session I am using at the time to call this python script?

Upvotes: 0

Views: 24

Answers (0)

Related Questions