I need to use Pyomo with Ipopt solver on Google-Colab.

In order to install it I did as follows: enter image description here

Now I need to use it , I get the following error ? ApplicationError: No executable found for solver 'ipopt'

enter image description here

How can I resolve it ?


If your notebook could be executed both on Colab or on a different environment (such as a local Jupyter notebook), you could add a couple of checks, before downloading and reinstalling pyomo and ipopt every time, as follows:

import shutil
import sys
import os.path

if not shutil.which("pyomo"):
    !pip install -q pyomo

if not (shutil.which("ipopt") or os.path.isfile("ipopt")):
    if "google.colab" in sys.modules:
        !wget -N -q "https://ampl.com/dl/open/ipopt/ipopt-linux64.zip"
        !unzip -o -q ipopt-linux64
            !conda install -c conda-forge ipopt 

The following package installation should be done before staring the Pyomo model

!pip install pyomo 
from pyomo.environ import *
import matplotlib.pyplot as plt
!wget -N -q "https://ampl.com/dl/open/ipopt/ipopt-linux64.zip"
!unzip -o -q ipopt-linux64

Then you can run your NLP model

model = AbstractModel()
model.x = Var(bounds=(0,1.2), within=Reals)
model.obj1 = Objective(expr=model.x**2, sense=maximize)
#opt = SolverFactory('ipopt')
opt=SolverFactory('ipopt', executable='/content/ipopt')
instance = model.create_instance()
results = opt.solve(instance) # solves and updates instance
print('OF= ',value(instance.obj1))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.