Installing Python API

Questions on using the GAMS APIs (Python, .NET, etc.)
Post Reply
cladelpino
User
User
Posts: 73
Joined: 1 year ago

Installing Python API

Post by cladelpino » 11 months ago

I'm having trouble with the install of the Python api.

I ran setup.py install from an elevated prompt without errors, but when I try to run transport.py from my IDE (VSCode) it rises the following exception: ModuleNotFoundError, No module named 'workspace'

What can be wrong ?

Best regards!

cladelpino
User
User
Posts: 73
Joined: 1 year ago

Re: Installing Python API

Post by cladelpino » 11 months ago

Examining workspace.pyd with dependency walker show a link failure to c:\gams\win64\24.2\PYTHON27.DLL. Can this be related to the problem, since I'm trying to call it from python 3 ? Inside the link it show failures at several windows libraries and MSVCR90.

Clemens
Posts: 19
Joined: 1 year ago

Re: Installing Python API

Post by Clemens » 11 months ago

The GAMS Python API comes in separate directories for different versions of Python. Please have a look at the 'Getting Started' section of the tutorial and make sure that you install the correct files for your version of Python:
https://www.gams.com/latest/docs/apis/e ... index.html

Best,
Clemens

cladelpino
User
User
Posts: 73
Joined: 1 year ago

Re: Installing Python API

Post by cladelpino » 11 months ago

From "Getting Started"
Examples using the API are located in apifiles/Python while the API itself is found in apifiles/Python/api for Python 2.7, in apifiles/Python/api_26 for Python 2.6 (Windows and Linux only), in apifiles/Python/api_34 for Python 3.4 and in apifiles/Python/api_36 for Python 3.6.
I don't have that many folders in GAMS 24.2.3, I only have apifiles\Python\api and apifiles\Python\api_26. I ran setup.py from apifiles\Python\api since my Python version is 3.6

Clemens
Posts: 19
Joined: 1 year ago

Re: Installing Python API

Post by Clemens » 11 months ago

I read this over, sorry. Support for Python 3.6 was added recently in GAMS 24.8.4. If you ran the setup script from the directory 'api', you have installed the Python 2.7 version which is not compatible with Python 3.6

Best,
Clemens

cladelpino
User
User
Posts: 73
Joined: 1 year ago

Re: Installing Python API

Post by cladelpino » 11 months ago

Ok, so two other questions:

1. How can I correctly uninstall the API ?
2. When I have Py 2.7 and 3.6 coexisting on the same machine, is there any extra step needed to make sure the API installs properly for 2.7 ?

Clemens
Posts: 19
Joined: 1 year ago

Re: Installing Python API

Post by Clemens » 11 months ago

1. The GAMS Python API is installed using distutils. As far as I know there is no automatic way of uninstalling a package/module that was installed using distutils. If you have accidentally installed the wrong version of GAMS Python API files, you might try to run the setup.py script from the correct folder in order to overwrite the existing files. If you really want to get rid of them, you need to delete them manually.

2. Multiple Python installations are no problem. You just need to run the appropriate setup.py script with the python interpreter that belongs to your specific python version. In your case you need to make sure that you execute the python interpreter of version 2.7 and run the setup.py script from the "api" directory.

Best,
Clemens

cladelpino
User
User
Posts: 73
Joined: 1 year ago

Re: Installing Python API

Post by cladelpino » 11 months ago

Seems to be working perfectly. Thank you Clemens!

Post Reply