PyPSA / linopy

Linear optimization with N-D labeled arrays in Python
https://linopy.readthedocs.io
MIT License
165 stars 51 forks source link

Problem when trying to use gurobi and linopy, on a .exe generated by auto-py-to-exe. #382

Closed KanaBaradei closed 10 hours ago

KanaBaradei commented 1 day ago

Dear all,

I can run my script without problems using Visual Studio Code, however when I create the .exe using autopytoexe the following error appears on the console:

image

I was using pyomo on the past and it worked both on VSC and the .exe. I'm wondering if it is a problem with linopy not being able to call gurobi correctly in this situation?

KanaBaradei commented 1 day ago

Looking at the files I found: image and: image I'm not a programmer and my knowledge is very limited so I don't know why it can't find the solver on the .exe but it can on the VSC. Any help is greatly appreciated.

lkstrp commented 1 day ago

This is not related to linopy, might be an issue with pyinstaller or is simply wrong usage.

Some things to keep in mind:

Without more information about your script and the pyinstaller command, this cannot be debugged.

KanaBaradei commented 1 day ago

Gurobipy is installed. I'm running the script in VSC and everything works, however when I run that same .exe on this exact same machine it throws the error shown above. The linopy part of the script is very basic, I construct a model and then solve it. The commands sent to pyinstaller are: pyinstaller --noconfirm --onefile --console "path to the file". I already had this same thing working with pyomo and the executable worked. Maybe there is a problem in paths or something?

KanaBaradei commented 1 day ago

Problem solved, for anyone that has this issue in the future: I downloaded one of the examples of GUROBI directly from their website, ran it on Visual Studio Code, verified that it worked. Created the .exe and found that one module was missing, added it to hidden options in pyinstaller and then another one popped. After 3 iterations adding the missing modules each time it finally worked. After that I went back to my linopy script and added those modules and it finally worked.

This are the modules: --hidden-import "gurobipy._util" --hidden-import "gurobipy._attrutil" --hidden-import "gurobipy._modelutil" Hope this helps anyone in the future.

@lkstrp thank you for your time. It was indeed a problem with pyinstaller and gurobi.

lkstrp commented 10 hours ago

Great, that you could resolve this!