2

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.

  • Could you give more details on the platform that you are using to test it? Does it help to pass the `--runtime-tmpdir PATH` argument to pyinstaller? Does it work with `remote=True`? – John Hedengren Feb 13 '21 at 22:50
  • 1
    Hi John, thanks for your reply! I am working on a 64 bit Windows 10 OS, but will eventually want a 32 bit windows version. I have confirmed that the application does run correctly while setting remote=True. – Jayson McAllister Feb 14 '21 at 15:20
  • 1
    I also tried using the --runtime-tmpdir PATH command for pyinstaller. the command looks like this: "pyinstaller GekkoTest.spec --onefile --runtime-tmpdir PATH" where PATH is the location of the spec/py files. Im not overly confident this is the PATH you meant, as I dont have a lot of experience with pyinstaller. – – Jayson McAllister Feb 14 '21 at 16:02
  • Instead of updating your question with an answer, please post your answer as an actual answer under your own post and accept it, so that users know, that this problem is solved – user8408080 Feb 15 '21 at 14:58

1 Answers1

2

"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