User Tools

Site Tools


platform:segmentation_fault_when_using_python_api_with_3rd_party_libraries

Segmentation fault when using Python API with 3rd party libraries

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:

#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.

IMPRESSUM / LEGAL NOTICEPRIVACY POLICY platform/segmentation_fault_when_using_python_api_with_3rd_party_libraries.txt · Last modified: 2019/07/24 07:56 by Clemens Westphal