KNITRO on Jupyter notebook & Atom

Dear all,

I am trying out KNITRO solver with a toy example:

using JuMP, KNITRO
model = JuMP.Model(with_optimizer(KNITRO.Optimizer))
@variable(model, x1 >= 0)
@variable(model, x2 >= 0)
@constraint(model, -1.5 * x1 + 2.0 * x2 == 2.0)
JuMP.optimize!(model)

It works just fine on a terminal (iTerm), VScode.
However Jupyter notebook and Atom return the same error:

error compiling Type: error compiling #Optimizer#36: error compiling Type: could not load library "libknitro.dylib/lib/libknitro.dylib"
dlopen(libknitro.dylib/lib/libknitro.dylib, 1): image not found

Stacktrace:
 [1] (::OptimizerFactory)() at /Users/singingkim/.julia/packages/JuMP/MsUSY/src/JuMP.jl:99
 [2] #set_optimizer#77(::Bool, ::typeof(set_optimizer), ::Model, ::OptimizerFactory) at /Users/singingkim/.julia/packages/JuMP/MsUSY/src/optimizer_interface.jl:38
 [3] #Model#7 at ./none:0 [inlined]
 [4] Model(::OptimizerFactory) at /Users/singingkim/.julia/packages/JuMP/MsUSY/src/JuMP.jl:193
 [5] top-level scope at In[2]:2

Other solvers (Ipopt, Gurobi, Mosek) are working properly on any IDE.
Can anyone give me a piece of advice on this?

Pkg.status():

  [c52e3926] Atom v0.11.3
  [a9b2a840] Complementarity v0.6.0
  [a93c6f00] DataFrames v0.19.4
  [31c24e10] Distributions v0.21.5
  [2e9cd046] Gurobi v0.7.2
  [7073ff75] IJulia v1.20.0
  [b6b21f68] Ipopt v0.6.1
  [4076af6c] JuMP v0.20.1
  [e5e0dc1b] Juno v0.7.2
  [67920dd8] KNITRO v0.7.3 #master (https://github.com/JuliaOpt/KNITRO.jl.git)
  [23992714] MAT v0.6.0
  [6405355b] Mosek v1.0.4
  [1ec41992] MosekTools v0.9.1
  [82193955] SCIP v0.9.1

The build process of Knitro.jl has been updated to support Jupyter notebook and Atom, which do not load the environment variables by default. Here, it seems that the issue is related to a mispecified path to Knitro shared library.

What is the output of the following command?

julia> KNITRO.libknitro

Thank you for the response. It shows as follows:

julia> KNITRO.libknitro
"libknitro.dylib/lib/libknitro.dylib"

I am afraid that the absolute path to libknitro.dylib is not recognized properly. I will open an issue on KNITRO.jl.

A quick (and hacky) fix is to set manually the absolute path in KNITRO/deps/deps.jl.

I appreciate your solution. Updating constants in deps.jl as below fixed my issue. Thanks!

const libknitro = "/Users/singingkim/knitro-12.0.0-z-MacOS-64/lib/libknitro.dylib"
const amplexe = "/Users/singingkim/knitro-12.0.0-z-MacOS-64/knitroampl"

This PR should resolve your issue: