Search code examples
pythonpyinstallergekko

Compiling Gekko with Pyinstaller


I am wondering if it is possible, or if anyone has any experience with, compiling the gekko optimization package with pyinstaller into an exe. As a test case, I am using the HS 71 Benchmark case from the gekko optimization website (https://gekko.readthedocs.io/en/latest/examples.html). I am using a 64 bit windows 10 os. This test case runs correctly in my Spyder environment. The exe also runs correctly when remote=True. I have packaged the code into an exe with the modification to run locally (m = GEKKO(remote=False)), and am running into errors while trying to run the exe.

The application is created successfully using the command: pyinstaller GekkoTest.spec

I have modified the spec file to include the hidden import 'gekko'

Upon running the resulting executable, it fails with an error saying the results.json file is not found. I have verified that the file (along with some other files) are not created in the tmp directory during execution of the application (I compared the files created while running in spyder to the files created by running the exectuable). I think Gekko optimization uses C/fortran code to run the algorithms as they are not native to python. After finding the solution to the optimization problem, it is written to a json file and loaded back into python. My guess is that pyinstaller does not include some of the required files in the creation of its executable.

Any suggestions with this problem would be much appreciated. Thank you.

UPDATE: "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." - bwoodsend from pyinstaller google group

After implementing this solution, the executable is now working. Thanks everyone for the suggestions.


Solution

  • "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." - bwoodsend from pyinstaller google group