python-3.xsubprocessgams-math

How to run GAMS from python?


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.


Solution

  • 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: https://www.gams.com/latest/docs/API_PY_OVERVIEW.html

    I personally have experience using GAMS in a Jupyter Notebook with GAMS Magic, which works pretty well! Check here on how to use it: https://www.gams.com/latest/docs/API_PY_MAGIC.html

    Hope it helps!