Pyinstaller and Gekko Optimization

87 views
Skip to first unread message

Jayson Mcallister

unread,
Feb 13, 2021, 6:13:34 AM2/13/21
to PyInstaller
Hello. I am trying to package a standalone exe that uses Gekko Optimization.  Pyinstaller successfully compiles the application but it fails to run completely through the script. As a test case, I have used the  HS 71 Benchmark  example directly from the Gekko Optimization website (https://gekko.readthedocs.io/en/latest/examples.html). I have modified the problem to run locally (instead of on gekko servers) and it runs successfully within spyder.

I have modified the .spec file to include hidden imports from Gekko (below)
-------------------------------------------------------------------
# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['GekkoTest.py'],
             pathex=['C:\\Users\\jcm\\.spyder-py3\\OTSG'],
             binaries=[],
             datas=[],
             hiddenimports=['gekko'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='GekkoTest',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True )
 -------------------------------------------------------------------

Upon running the script I get errors related to results.json not found. Long story short, the python executable is not creating the problem's solution files. I am not completely familiar, but I believe Gekko optimization solves problems in fortran/C and writes to json files which are then loaded back into python. It is likely that pyinstaller is not wrapping up some of the necessary files related to these other languages.  Does anyone know a way to make Gekko Optimization work correctly using pyinstaller?

Thanks in advance for suggestions.

bwoodsend

unread,
Feb 15, 2021, 7:07:37 AM2/15/21
to PyInstaller

You just need to tell PyInstaller to include Gekko’s data files. Edit your spec putting from PyInstaller.utils.hooks import collect_data_files at the top, set the datas=[] argument to datas=collect_data_files('gekko') then rebuild with pyinstaller GekkoTest.spec.

Reply all
Reply to author
Forward
0 new messages