Gurobi license issue

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

Solved on the Github issue.


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.

    if @isdefined(GUROBI_ENV)

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!

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> const x = 1

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

The answer is @ccoffrin’s reply from the Github

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,

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

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()

when creating the environment variable.

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:

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?

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):

ENV["GRB_LICENSE_FILE"] = "/full/path/to/file.lic"
import Pkg"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.

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:

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

import Pkg
using Gurobi
@show Gurobi. _GUROBI_VERSION
@show Gurobi.Env()

To get this error:

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

 [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

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


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

Here’s the output:

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

 [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?

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:

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


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.

1 Like

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