# Gurobi license issue

**URL:** https://discourse.julialang.org/t/gurobi-license-issue/36547
**Category:** Optimization (Mathematical)
**Created:** [March 26, 2020, 10:11am UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547 "2020-03-26T10:11:51Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Nicolas\_Slosse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nicolas_slosse/32/13634_2.png) [@Nicolas\_Slosse](https://discourse.julialang.org/u/Nicolas_Slosse)
#### Post date: [March 26, 2020, 10:11am UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/1 "2020-03-26T10:11:51Z")

</div>

Dear forum,

I have installed a fresh version of Gurobi.jl and JuMP for Julia Version 1.3.1 on a linux server.

When making call to Gurobi 9.0 from Julia, I bump on the following error message :

ERROR: LoadError: Invalid Gurobi license

After some research on the internet, I have checked that :

```
my Gurobi license file was valid (N.B. this is an evaluation licence)
all environment variables are properly set
gurobi works well on its own or when used embedded in python.

```

Do you have any idea what may cause this error ?

Thank you in advance,

Nicolas Slosse

P.S. : I have opened a github ticket on this issue [Invalid Gurobi license · Issue #299 · jump-dev/Gurobi.jl · GitHub](https://github.com/JuliaOpt/Gurobi.jl/issues/299)

---

<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: [March 26, 2020, 1:38pm UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/2 "2020-03-26T13:38:45Z")

</div>

Solved on the Github issue.

---

<div class="post-metadata">

### Author: ![iharjunk](https://avatars.discourse-cdn.com/v4/letter/i/e0b2c6/32.png) [@iharjunk](https://discourse.julialang.org/u/iharjunk)
#### Post date: [September 2, 2020, 4:28am UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/3 "2020-09-02T04:28:41Z")

</div>

Hi!

Thank you for this solution, which I have used already since 1-2 years back. Nevertheless, I did all of the above and am using a Gurobi floating license (4 instances). Still it sometimes claims 2 or 3 licenses to solve one instance. Any ideas how to find the root-cause for this “random” behavior? I am doing consecutive optimization runs, and after each run I clear the environmental variable.

```julia
    GC.gc()
    if @isdefined(GUROBI_ENV)
        Gurobi.free_env(GUROBI_ENV)
    end

```

Also tried to put a “sleep (1)” after this in order to give some time before asking for the next license but this would not solve the issue.

In fact, even when only solving one problem, this happens. Often it takes place when running new instances (starting Julia in Atom). After repeatedly calling the optimizer it mostly stops claiming multiple licenses. However, this is random so I am a bit suspecting this relates to some communication problem between the client and license server (Gurobi?).

Would be nice to really get this under control and am happy for any further tips!

---

<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: [September 3, 2020, 2:44am UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/4 "2020-09-03T02:44:48Z")

</div>

You should not be calling `GC.gc()` or `free_env`. The correct way is to call `const GUROBI_ENV = Gurobi.Env()` once _only_. If you re-include the script, bad things can happen. Indeed, in Julia 1.5 there is now a nice error:

```Julia
julia> const x = 1
1

julia> const x = 2
WARNING: redefinition of constant x. This may fail, cause incorrect answers, or produce other errors.
2

```

The answer is @ccoffrin’s [reply from the Github](https://github.com/jump-dev/Gurobi.jl/issues/299#issuecomment-685838303)

> For anyone that may come across this thread, you may run into issues if running the same script multiple times, for example while doing model development. In that case, I have used the following approach for defining the env constant,

```julia
if !(@isdefined env)
    const env = Gurobi.Env()
end

```

---

<div class="post-metadata">

### Author: ![iharjunk](https://avatars.discourse-cdn.com/v4/letter/i/e0b2c6/32.png) [@iharjunk](https://discourse.julialang.org/u/iharjunk)
#### Post date: [September 3, 2020, 6:42am UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/5 "2020-09-03T06:42:07Z")

</div>

Thank you!

Sorry that I did not mention it … I have read your earlier posts on this topic and use

> if optimizer == Gurobi.Optimizer && !@isdefined(GUROBI\_ENV)  
> const GUROBI\_ENV = Gurobi.Env()  
> end

when creating the environment variable.

---

<div class="post-metadata">

### Author: ![arseny-sandaar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arseny-sandaar/32/22568_2.png) [@arseny-sandaar](https://discourse.julialang.org/u/arseny-sandaar)
#### Post date: [March 5, 2021, 12:27pm UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/6 "2021-03-05T12:27:24Z")

</div>

I also have an issue with invalid license.  
I have Gurobi 9.10 and Julia v"1.5.3".  
My license is valid.

I set the path to gurobi.lic for my Gurobi version for ENV[“GRB\_LICENSE\_FILE”] = “my\_path”  
When I do this:

```julia
const env = Gurobi.Env() # Do ONE license check
model = Model(() -> Gurobi.Optimizer(env))

```

it gives an error about an invalid license.

Any ideas? I am very new in Julia and in using Gurobi.  
Could anyone list steps for a very “dummy” user, please?

---

<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: [March 5, 2021, 7:20pm UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/7 "2021-03-05T19:20:45Z")

</div>

There are multiple reasons you could get the invalid license error:

- The path is not the full path to the license
- You didn’t validate the license using `grbgetkey`
- Your license has expired
- Your license is not valid for Gurobi 9.10

If you’ve checked those, try (replacing the full path as appropriate):

```nohighlight
ENV["GRB_LICENSE_FILE"] = "/full/path/to/file.lic"
import Pkg
Pkg.build("Gurobi")
using Gurobi
@show Gurobi. _GUROBI_VERSION
@show Gurobi.Env()

```

and if you still get an error, please start a new post with the full printout of the error messages.

---

<div class="post-metadata">

### Author: ![anon94806364](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@anon94806364](https://discourse.julialang.org/u/anon94806364)
#### Post date: [June 22, 2021, 10:15pm UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/8 "2021-06-22T22:15:00Z")

</div>

I also happen to have the same error. This occurred when I tried installing Gurobi & JuMP on an HPC; I know that Gurobi academic license works as I had tested my Python script on this HPC.

I followed the instructions above:

```julia
ENV["GUROBI_HOME"] = "/home/b2jia/anaconda3/pkgs/gurobi-9.1.2-py38_0/"
ENV["GRB_LICENSE_FILE"] = "/home/b2jia/gurobi.lic"

import Pkg
Pkg.add("Gurobi")
Pkg.build("Gurobi")
using Gurobi
@show Gurobi. _GUROBI_VERSION
@show Gurobi.Env()

```

To get this error:

```julia
Gurobi._GUROBI_VERSION = v"9.1.2"
Gurobi Error 10009: Failed to obtain a valid license

Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] Gurobi.Env()
   @ Gurobi ~/.julia/packages/Gurobi/HtUHB/src/MOI_wrapper.jl:89
 [3] top-level scope
   @ show.jl:955
 [4] eval
   @ ./boot.jl:360 [inlined]
 [5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1094

```

---

<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: [June 22, 2021, 10:31pm UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/9 "2021-06-22T22:31:42Z")

</div>

Does your license support 9.1.2? Are you sure your python code is using the same license file?

---

<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: [June 22, 2021, 10:38pm UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/10 "2021-06-22T22:38:54Z")

</div>

Do

```nohighlight
using Gurobi
a = Ref{Ptr{Cvoid}}()
ret = GRBloadenv(a, C_NULL)
Gurobi._check_ret(a[], ret)

```

Edit: [Improve error handling of license problems by odow · Pull Request #418 · jump-dev/Gurobi.jl · GitHub](https://github.com/jump-dev/Gurobi.jl/pull/418)

---

<div class="post-metadata">

### Author: ![anon94806364](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@anon94806364](https://discourse.julialang.org/u/anon94806364)
#### Post date: [June 22, 2021, 11:50pm UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/11 "2021-06-22T23:50:32Z")

</div>

Here’s the output:

```julia
Gurobi Error 10009: HostID mismatch (licensed to 4b4b03d9, hostid is 587e591)

Stacktrace:
 [1] _check_ret(env::Ptr{Nothing}, ret::Int32)
   @ Gurobi ~/.julia/packages/Gurobi/HtUHB/src/MOI_wrapper.jl:331
 [2] top-level scope
   @ In[16]:4
 [3] eval
   @ ./boot.jl:360 [inlined]
 [4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1094

```

I guess here is where I am confused. I used `grbgetkey` in `/home/b2jia/anaconda3/pkgs/gurobi-9.1.2-py38_0/bin` to validate the license, and `gurobi_cl` can indeed find this key. Am I somehow validating incorrectly?

---

<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: [June 23, 2021, 12:38am UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/12 "2021-06-23T00:38:41Z")

</div>

The HostID mismatch suggests you have validated the license on a computer that is different to the one you are currently on.

I suggest you contact Gurobi support:

> **[How do I resolve an "ERROR 10009: HostID mismatch"?](https://support.gurobi.com/hc/en-us/articles/360055275311-How-do-I-resolve-an-ERROR-10009-HostID-mismatch-)**
>
> The errorERROR 10009: HostID mismatch indicates that the license file was generated for a machine with a different host ID. If the license file previously worked on the same machine, then something...

(Gurobi.jl is not officially supported by Gurobi, and is maintained by the community.)

---

<div class="post-metadata">

### Author: ![anon94806364](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@anon94806364](https://discourse.julialang.org/u/anon94806364)
#### Post date: [June 23, 2021, 2:21am UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/13 "2021-06-23T02:21:21Z")

</div>

Thank you for this, and sorry to piggy-back off another post. If someone experiences similar errors as I did, I was able to resolve my issue by contacting my HPC admin. Our primary network adapter may have been modified.

---

<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: [June 23, 2021, 9:04pm UTC](https://discourse.julialang.org/t/gurobi-license-issue/36547/14 "2021-06-23T21:04:38Z")

</div>

Great. I made a new release of Gurobi.jl, so people should see more informative messages in future and not just “Failed to obtain a valid license.”
