I am trying to run a GAMS file from a python file. I am using vscode on a macbook.
So far, I have been able to open the desired GAMS file from Python using subprocess. To do this I have used the following block of code:
import subprocess
subprocess.run(['open', "/Users/tk/GAMS/sim.gms"], check=True)However, it just opens the GAMS file but does not execute it. I need to execute the GAMS file and after the GAMS execution is complete, the python program should continue.
How do I do this? Any help is much appreciated. PS. There is a tutorial on GAMS, but I could not understand it as it seemed too complex to me.
2 Answers
You can check in the docs here on how to use GAMS' Python API. There is a "Getting Started" section where you can download all libs needed:
I personally have experience using GAMS in a Jupyter Notebook with GAMS Magic, which works pretty well! Check here on how to use it:
Hope it helps!
I've never used gams but after a quick look at it sounds like /Users/tk/GAMS/sim.gms is not the file to be executed but the input file to be given as argument to the gams executable.
UG_TutorialQuickstart_RunningTheJob
So you should try something like :
import subprocess
subprocess.run(['/opt/gams/gams24.3_linux_x64_64_sfx/gams', '/Users/tk/GAMS/sim.gms'], check=True)Notice : there is a GAMS python API which could give you a more portable solution.
1