I downloaded the Knitro solver files. To use it, I need to activate the ampl license. However, I couldn’t activate the license and so I can’t use knitro. Can you help me?
Thank you for reaching out. Which error did you get when you tried to activate the license?
To use Knitro with Pyomo you should just need to pass the path to it to SolverFactory. Are you getting a license error when you try to use it?
You can also try with the modules for Python that also work with Pyomo: AMPL Modules for Python — AMPL Resources
Could you please check the value of os.envion["AMPL_LICFILE"]? Somehow seems to have a different value than the one in .bashrc. Alternatively, you could also update the value in .bashrc to that one and move the license to the location where Knitro is looking for it.
Since os.environ["AMPL_LICFILE] is pointing to $HOME/.ampl/ampl.lic. Knitro will be looking for the license there. You may need to restart the notebook in order to load the new environment variable value in .bashrc.
In the first argument of SolverFactory you should use “baronnl” instead of “baron” since Pyomo will try to use a bar file otherwise.
In case you used the python modules, the code for any solver would be:
!pip install amplpy pyomo -q
!python -m amplpy.modules install <solver-name> -q
!python -m amplpy.modules activate <license-uuid>
from amplpy import modules
import pyomo.environ as pyo
solver_name = "<solver-name>"
solver = pyo.SolverFactory(solver_name+"nl", executable=modules.find(solver_name), solve_io="nl")








