# KNITRO on Jupyter notebook & Atom

**URL:** <https://discourse.julialang.org/t/knitro-on-jupyter-notebook-atom/30542>\
**Category:** Optimization (Mathematical)\
**Created:** [October 31, 2019, 2:36pm UTC](https://discourse.julialang.org/t/knitro-on-jupyter-notebook-atom/30542 "2019-10-31T14:36:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SingingKim](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@SingingKim](https://discourse.julialang.org/u/SingingKim)\
**Post date:** [October 31, 2019, 2:36pm UTC](https://discourse.julialang.org/t/knitro-on-jupyter-notebook-atom/30542/1 "2019-10-31T14:36:46Z")

</div>

Dear all,

I am trying out KNITRO solver with a toy example:

```julia
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:

```julia
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():

```julia
  [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

```

---

<div class="post-metadata">

**Author:** ![frapac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frapac/32/6879_2.png) [@frapac](https://discourse.julialang.org/u/frapac)\
**Post date:** [November 4, 2019, 11:16am UTC](https://discourse.julialang.org/t/knitro-on-jupyter-notebook-atom/30542/2 "2019-11-04T11:16:16Z")

</div>

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
julia> KNITRO.libknitro

```

---

<div class="post-metadata">

**Author:** ![SingingKim](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@SingingKim](https://discourse.julialang.org/u/SingingKim)\
**Post date:** [November 4, 2019, 12:33pm UTC](https://discourse.julialang.org/t/knitro-on-jupyter-notebook-atom/30542/3 "2019-11-04T12:33:34Z")

</div>

Thank you for the response. It shows as follows:

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

```

---

<div class="post-metadata">

**Author:** ![frapac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frapac/32/6879_2.png) [@frapac](https://discourse.julialang.org/u/frapac)\
**Post date:** [November 4, 2019, 2:52pm UTC](https://discourse.julialang.org/t/knitro-on-jupyter-notebook-atom/30542/4 "2019-11-04T14:52:15Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![SingingKim](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@SingingKim](https://discourse.julialang.org/u/SingingKim)\
**Post date:** [November 4, 2019, 3:37pm UTC](https://discourse.julialang.org/t/knitro-on-jupyter-notebook-atom/30542/5 "2019-11-04T15:37:10Z")

</div>

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

```julia
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"

```

---

<div class="post-metadata">

**Author:** ![frapac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frapac/32/6879_2.png) [@frapac](https://discourse.julialang.org/u/frapac)\
**Post date:** [November 4, 2019, 4:07pm UTC](https://discourse.julialang.org/t/knitro-on-jupyter-notebook-atom/30542/6 "2019-11-04T16:07:15Z")

</div>

This PR should resolve your issue:  
[https://github.com/JuliaOpt/KNITRO.jl/pull/135](https://github.com/JuliaOpt/KNITRO.jl/pull/135)
