"WARNING: Could not locate the 'ipopt' executable" and Pyomo (OS: Windows)

Viewed 700

I have been trying to make ipopt work on pyomo. I've downloaded pyomo (version 5.7.3) and ipopt using Anaconda Navigator and I'm using Spyder to edit and run my .py codes. I've been using the following code from the pyomo tutorial in order to understand whether ipopt is successfully installed and works.

import pyomo.environ as pyo
from pyomo.opt import SolverFactory
model = pyo.ConcreteModel()
model.nVars = pyo.Param(initialize=4)
model.N = pyo.RangeSet(model.nVars)
model.x = pyo.Var(model.N, within=pyo.Binary)
model.obj = pyo.Objective(expr=pyo.summation(model.x))
model.cuts = pyo.ConstraintList()
opt = SolverFactory('ipopt')
opt.solve(model) 

# Iterate, adding a cut to exclude the previously found solution
for i in range(5):
   expr = 0
   for j in model.x:
       if pyo.value(model.x[j]) < 0.5:
           expr += model.x[j]
       else:
           expr += (1 - model.x[j])
   model.cuts.add( expr >= 1 )
   results = opt.solve(model)
   print ("\n===== iteration",i)
   model.display()

When I set opt = SolverFactory('ipopt') and run the code, it gives me the following warning:

WARNING: Could not locate the 'ipopt' executable, which is required for solver ipopt

My first try to solve this problem by myself is to manually download the ipopt executable (ipopt 3.11.1-win64) from the link below:

https://www.coin-or.org/download/binary/Ipopt/

Afterwards, I extracted the files and placed them into the pyomo solver location:

C:\Anaconda\envs\myenv\Lib\site-packages\pyomo\solvers\plugins\solvers

This didn't work, so I also tried specifying the path to the ipopt executable using the code:

opt = pyo.SolverFactory("ipopt", executable="C:\Anaconda\envs\myenv\Lib\site-packages\pyomo\solvers\plugins\solvers\ipopt\bin\ipopt.exe")

However, doing this gives me the following warning:

WARNING: Failed to create solver with name 'ipopt': Failed to set executable
    for solver ipopt. File with name=C:\Anaconda\envs\myenv\Lib\site-packages\
    pyomo\solvers\plugins\solvers\ipopin\ipopt.exe
    either does not exist or it is not executable. To skip this validation,
    call set_executable with validate=False.

Reminder that the part ipopin\ipopt.exe was not a typo. I don't know why it happened. I also tried copy-pasting the executable outside the bin folder and placing it in the ipopt folder instead:

opt = pyo.SolverFactory("ipopt", executable="C:\Anaconda\envs\myenv\Lib\site-packages\pyomo\solvers\plugins\solvers\ipopt\ipopt.exe")

Unfortunately I still get the WARNING. Could not locate the 'ipopt' executable, which is required for solver ipopt in the end.

I also tried downloading the ipopt executable from the link below but ipopt.exe is eliminated by my virus scanner as it considers the downloaded file as a threat:

https://projects.coin-or.org/CoinBinary/browser/binary/Ipopt/Ipopt-3.13.2-win64-msvs2019-md.zip?rev=1072

Is there another way I can try to make IPOPT work in this case?

1 Answers

if you run your jupyter notebook from the anaconda then you should be able to see your solver in the installed list of anaconda

Related