GAMS API Python

Questions on using the GAMS APIs (Python, .NET, etc.)
Post Reply
Romario7
User
User
Posts: 2
Joined: 5 months ago

GAMS API Python

Post by Romario7 » 5 months ago

Hi all,

I am a beginner with Python but I would like to run my "model.gms" file through it.
My GAMS version is 25.1.1 32 bit while I run the 3.6 32 bit version of Python from RT-Lab.
From the transport1.py file I run only the very first rows to check if the GAMS library is imported:
from __future__ import print_function
from gams import *
import os
import sys

but I get the following error:
Traceback (most recent call last):
File "D:\03_RTLAB_Workspace\AutoPython\PythonScript.py", line 2, in <module>
from gams import *
File "D:\03_RTLAB_Workspace\AutoPython\gams\__init__.py", line 8, in <module>
from .workspace import *
ImportError: DLL load failed: %1 is not a valid Win32 application.

Do you have any suggestion to solve this issue?

I take the opportunity also to ask the following:
- Do the API files have to be in the same folder of my model's folder?
- Do I have to install the API also in GAMS? If so, I tried to run the code suggested in the Getting started section (cd api && python setup.py install && cd ..) but I get the following: "Error 140: unknown symbol, which is linked to the above-mentioned suggested command".

Thank you for your support!

Clemens
Posts: 27
Joined: 2 years ago

Re: GAMS API Python

Post by Clemens » 5 months ago

Hi,

The error is most likely caused by a bitness mismatch of your GAMS version including the Python API and your version of Python itself. Please double check your Python version if it is really 32 bit by just launching the live interpreter on the command line and looking at the output.

Regarding the other questions: Python needs to somehow find the files of the GAMS Object-oriented Python API (<Path/To/GAMS>/apifiles/Python/api_36). This can be done by setting the PYTHONPATH or by installing the API into the site-packages directory of your Python installation. (see https://www.gams.com/latest/docs/API_PY_TUTORIAL.html). It is in general not required (and not recommended) to copy the API files next to your model.

Please let me know if this helps.

Best,
Clemens

Romario7
User
User
Posts: 2
Joined: 5 months ago

Re: GAMS API Python

Post by Romario7 » 5 months ago

Clemens wrote:
5 months ago
Hi,

The error is most likely caused by a bitness mismatch of your GAMS version including the Python API and your version of Python itself. Please double check your Python version if it is really 32 bit by just launching the live interpreter on the command line and looking at the output.

Regarding the other questions: Python needs to somehow find the files of the GAMS Object-oriented Python API (<Path/To/GAMS>/apifiles/Python/api_36). This can be done by setting the PYTHONPATH or by installing the API into the site-packages directory of your Python installation. (see https://www.gams.com/latest/docs/API_PY_TUTORIAL.html). It is in general not required (and not recommended) to copy the API files next to your model.

Please let me know if this helps.

Best,
Clemens

Hi Clemens,

Thank you very much for your quick reply!
I have just checked the version (import sys print (sys.version)): I have installed Python 2.7.12 (not 3.6) but still 32 bit, in accordance with the 32 bit of GAMS.

Roberto


I have just updated Python to the new version 3.6 64 bit, also in accordance with my computer bitness. In fact, RT-Lab by default installs a 32 bit version of Python. Now I can import the GAMS API, I have to discover the way it works now!

Thank you again

Clemens
Posts: 27
Joined: 2 years ago

Re: GAMS API Python

Post by Clemens » 5 months ago

Then it was perhaps a mismatch in the version of the Python API and the Python interpreter. Both the bitness as well as the version (2.7, 3.6 etc) need to match. Good to hear that you got it working.
You have probably seen the tutorial already, but in case you did not, here it is: https://www.gams.com/latest/docs/API_PY ... L_EXAMPLES
This is a good resource to get started with the API since it explains the most important aspects of the API and how to use them.

Best,
Clemens

Post Reply