1

I met this problem when running the exe after packaging python files using pyinstaller. My python file is an optimization model using pyomo package, which calls gurobi and ipopt solvers. The ipopt solver runs well. When my gurobi exe program runs, it prints

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
ModuleNotFoundError: No module named 'GUROBI_RUN'
ERROR: Solver (gurobi) returned non-zero return code (1)
ERROR: See the solver log above for diagnostic information.
Traceback (most recent call last):
  File "main.py", line 136, in <module>
  File "main.py", line 131, in main
...

GUROBI_RUN is a py file in path 'C:\Users\******\.conda\envs\gurobi_env\Lib\site-packages\pyomo\solvers\plugins\solvers'

I have tried several methods including:

  1. adding parameters into spec files.
a = Analysis(['main.py'],
pathex=['C:\\Users\\*****\\.conda\\envs\\gurobi_env\\Lib\\site-packages', 
'C:\\gurobi900'],
...
  1. write python code in main.py like
from pyomo.solvers.plugins.solvers import GUROBI_RUN
  1. adding hiddenimports into spec files
hiddenimports=['pyomo.solvers.plugins.solvers.GUROBI_RUN', 'pyomo.solvers', 'pyomo.common.plugins', ...],

My current method using pyinstaller is

  • run pyinstaller main.py in terminal
  • a spec file is generated automatically, then revise spec file, including adding pathex, adding hiddenimports, adding datas
  • run pyinstaller main.spec in terminal
  • run main.exe in terminal

My operating env is 134 INFO: PyInstaller: 4.1 134 INFO: Python: 3.7.6 (conda) 135 INFO: Platform: Windows-10-10.0.17763-SP0 150 INFO: UPX is not available.

1 Answers1

0

I solved this problem by a very stupid and primal method. Since my package is a file folder instead of a single big exe file, I just try to put the GUROBI_RUN.py file into the file folder, the same level of main.exe. And it works!!! My gurobi program can run regularly in exe now.

  • I rechecked my original methods 1, 2, 3, like adding pathx, adding ```from *** import GUROBI_RUN``` or ```import GUROBI_RUN``` after putting the py file next to main.py, and adding hidden imports. All of them are unnecessary once I put GUROBI_RUN.py next to the main.exe in the packaged file folder. All those parameters can be deleted. – Wayne Zhang Dec 17 '20 at 05:45