# LoadError: UndefVarError: Grisu not defined

**URL:** <https://discourse.julialang.org/t/loaderror-undefvarerror-grisu-not-defined/61000>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [May 12, 2021, 6:21am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-grisu-not-defined/61000 "2021-05-12T06:21:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![healyp](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@healyp](https://discourse.julialang.org/u/healyp)\
**Post date:** [May 12, 2021, 6:21am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-grisu-not-defined/61000/1 "2021-05-12T06:21:38Z")

</div>

I’m getting the above error with `JuMP` / `MathOptInterface` when I attempt to write a model to a file:

```julia
MOI.write_to_file(lp_model, gName*".lp")

```

I note that there has been some discussion about `Grisu` in a plots+1.6 context recently but this error has existed for me in previous (\< v1.6) versions – though I am now running 1.6.0.

Would anybody have any suggestions, please? Many thanks.

The first few lines of stacktrace are:

```julia
ERROR: LoadError: UndefVarError: Grisu not defined
Stacktrace:
  [1] write_function(io::IOStream, model::MathOptFormat.LP.InnerModel{Float64}, func::MathOptInterface.ScalarAffineFunction{Float64}, variable_names::Dict{MathOptInterface.VariableIndex, String})
    @ MathOptFormat.LP ~/.julia/packages/MathOptFormat/3cISG/src/LP/LP.jl:88
  [2] write_objective(io::IOStream, model::MathOptFormat.LP.InnerModel{Float64}, variable_names::Dict{MathOptInterface.VariableIndex, String})
    @ MathOptFormat.LP ~/.julia/packages/MathOptFormat/3cISG/src/LP/LP.jl:174
  [3] write(io::IOStream, model::MathOptFormat.LP.InnerModel{Float64})
    @ MathOptFormat.LP ~/.julia/packages/MathOptFormat/3cISG/src/LP/LP.jl:195
  [4] #5
    @ ~/.julia/packages/MathOptFormat/3cISG/src/MathOptFormat.jl:100 [inlined]
  [5] open(::MathOptFormat.var"#5#6"{MathOptFormat.LP.InnerModel{Float64}}, ::String, ::Vararg{String, N} where N; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base ./io.jl:330
  [6] open(::Function, ::String, ::String)

```

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [May 12, 2021, 7:22am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-grisu-not-defined/61000/2 "2021-05-12T07:22:34Z")

</div>

Have you tried to install the [Grisu package](https://github.com/JuliaAttic/Grisu.jl) ?

---

<div class="post-metadata">

**Author:** ![healyp](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@healyp](https://discourse.julialang.org/u/healyp)\
**Post date:** [May 12, 2021, 7:30am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-grisu-not-defined/61000/3 "2021-05-12T07:30:23Z")

</div>

Yes. Unless it should have been installed in some way other than the straightforward `add Grisu`; `using Grisu` way then it is not solving the issue.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 12, 2021, 7:32am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-grisu-not-defined/61000/4 "2021-05-12T07:32:47Z")

</div>

MathOptFormat.jl is deprecated. You can write directly from JuMP now.

```nohighlight
using JuMP
model = Model()
write_to_file(model, "model.lp")

```

[https://jump.dev/JuMP.jl/v0.21.8/manual/models/#Write-a-model-to-file](https://jump.dev/JuMP.jl/v0.21.8/manual/models/#Write-a-model-to-file)

You can also write directly from MathOptInterface:  
[https://jump.dev/MathOptInterface.jl/stable/submodules/FileFormats/overview/#Write-to-file](https://jump.dev/MathOptInterface.jl/stable/submodules/FileFormats/overview/#Write-to-file)

---

<div class="post-metadata">

**Author:** ![healyp](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@healyp](https://discourse.julialang.org/u/healyp)\
**Post date:** [May 12, 2021, 10:15am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-grisu-not-defined/61000/5 "2021-05-12T10:15:33Z")

</div>

Thank you. That’s nice to know.

However when I tried upgrading my JuMP package I got teh below. I’m sure I’m doing something wrong here.

```julia
(@v1.6) pkg> add JuMP@0.21.8
   Resolving package versions...
ERROR: Unsatisfiable requirements detected for package DataStructures [864edb3b]:
 DataStructures [864edb3b] log:
 ├─possible versions are: 0.9.0-0.18.9 or uninstalled
 ├─restricted to versions * by an explicit requirement, leaving only versions 0.9.0-0.18.9
 ├─restricted by compatibility requirements with JuMP [4076af6c] to versions: 0.18.0-0.18.9
 │ └─JuMP [4076af6c] log:
 │ ├─possible versions are: 0.18.3-0.21.8 or uninstalled
 │ └─restricted to versions 0.21.8 by an explicit requirement, leaving only versions 0.21.8
 └─restricted by compatibility requirements with Compose [a81c6b42] to versions: 0.11.0-0.17.20 — no versions left
   └─Compose [a81c6b42] log:
     ├─possible versions are: 0.6.1-0.9.2 or uninstalled
     └─restricted by compatibility requirements with PlotShapefiles [297584a0] to versions: 0.8.1-0.8.2
       └─PlotShapefiles [297584a0] log:
         ├─possible versions are: 0.1.0-0.2.2 or uninstalled
         └─restricted to versions * by an explicit requirement, leaving only versions 0.1.0-0.2.2

```

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 12, 2021, 8:38pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-grisu-not-defined/61000/6 "2021-05-12T20:38:47Z")

</div>

The error says that PlotShapeFiles requires Compose 0.8, which doesn’t support DataStructures 0.18, as required by JuMP.

Documentation: [3. Managing Packages · Pkg.jl](https://pkgdocs.julialang.org/v1/managing-packages/#conflicts)

That means you can’t use the latest versions of ~~Compose~~ PlotShapeFiles and JuMP together.

Either remove ~~Compose~~ PlotShapeFiles `] rm PlotShapeFiles`, or more preferably, use a Pkg environment to minimize the conflicts: [4. Working with Environments · Pkg.jl](https://pkgdocs.julialang.org/v1/environments/).

---

<div class="post-metadata">

**Author:** ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)\
**Post date:** [May 12, 2021, 10:01pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-grisu-not-defined/61000/7 "2021-05-12T22:01:44Z")

</div>

> [@odow](#):
>
> That means you can’t use the latest versions of Compose and JuMP together.

The latest version of Compose is 0.9.2, which is compatible with DataStructures 0.18. The issue is that PlotShapeFiles requires an old version of Compose.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 12, 2021, 10:15pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-grisu-not-defined/61000/8 "2021-05-12T22:15:23Z")

</div>

Ah, you’re right. I don’t know why I got confused.
