Segmentation fault when using Python API with 3rd party libraries

Frequently asked questions about GAMS

Moderator: aileen

Forum rules
Please ask questions in the other sub-forums
Locked
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Segmentation fault when using Python API with 3rd party libraries

Post by abhosekar »

Using the GAMS Python OO API in combination with third party libraries (e.g. pandas) might fail with a segmentation fault on Linux and Mac OS X. This problem occurs if the third party library loads a version of the shared library libstdc++ which is not compatible with the GAMS Python OO API. The solution is to force the loading of the libstdc++ version that is distributed with the GAMS system. This can be done by importing the gams module at the very beginning before all other modules. In order to make sure that the shared library is really loaded it is required to create an instance of type GamsDatabase (e.g. by calling GamsWorkspace.add_database()). The following example shows how this can be done:

Code: Select all

#import pandas as pd
from gams import *
if __name__ == "__main__":
    ws = GamsWorkspace()
 
    # create an instance of GamsDatabase in order to make sure the shared library is loaded
    ws.add_database()
 
    # now it should be possible to import pandas
    import pandas as pd
 
    # ... continue with your actual code
Another possible workaround is to convince the third party library to load the GAMS version of libstdc++ by setting the LD_LIBRARY_PATH or the DYLD_LIBRARY_PATH to the GAMS system directory.

All the mentioned solutions are just meant as workarounds. A better fix to the problem is to update the operating system to a newer version that comes with up-to-date system libraries.
Locked