EDIT: It turns out the shell that the subprocess module does not have the same directories assigned to the PATH variable as my system's shell. Thus the solution is simply to either call Maxima using the full path (found through which maxima
) or changing env={'PATH':maxima_paths}
in the subprocess.run() parameters. As @RobertDodier pointed out, this is not an issue with Maxima specifically.
I have a file called testMaxima.txt that contains the following Maxima code:
write_data([[1,2,3]], "test.txt");
This Maxima code creates the file test.txt
in the working directory.
I am looking to run this file using a Python script. I do not want to open Maxima (a math engine) manually in order to do this.
What I've tried: I know that I can run this file in Command Line/Terminal using maxima -b testMaxima.txt
and I have tried to use the python module subprocess
to emulate this code with the following python code:
import subprocess
subprocess.run("maxima -b testMaxima.txt", shell=True)
but this does not create the new test.txt
file like it should. If this helps, when I run
>>> subprocess.call("maxima -b testMaxima.txt", shell=True)
127
I get an output of 127. From what I understand, this means that the terminal can't find the given commands. However, there is no issues when I execute the code maxima -b testMaxima.txt
through the terminal directly, so I'm not sure why it cannot find the given commands. Does anyone have any thoughts on what I should try?
Thank you in advance!
EDIT: From @mkrieger 's advice, I am using a string "maxima -b testMaxima.txt"
instead of the sequence ["maxima", "-b", "testMaxima.txt"]
. Unfortunately, this does not make a difference.