When you want to change the values of Gurobi parameters, you have several options.
Setting parameters
From the Python API
You have several options to set parameters in the Python interface. Here are a few options to set the TimeLimit parameter:
m.Params.TimeLimit = 100.0
m.setParam(GRB.Param.TimeLimit, 100.0)
m.setParam("TimeLimit", 100.0)
For more details, please see Parameter Examples.
From other language APIs
For details for each API, please see the Parameter Examples section of the Reference Manual.
| C | |
|
| C++ | |
|
| C# | |
|
| Java | |
|
| Matlab | |
|
| R | |
|
| Visual Basic | |
Using the command-line interface (gurobi_cl)
For example:
> gurobi_cl TimeLimit=100 /opt/gurobi1302/linux64/examples/data/coins.lp
For further details, see How do I use the Gurobi Command Line Interface (gurobi_cl)?
Using a gurobi.env file
Another option is through a gurobi.env file.
Whenever the Gurobi library starts, it will look for gurobi.env in the current working directory and will apply any parameter changes contained therein. This is true whether the Gurobi library is invoked from the command-line tool, from the interactive shell, or from any of the Gurobi APIs.
Parameter settings are stored one per line in this file, with the parameter name first, followed by at least one space, followed by the desired value. Lines beginning with the # sign are comments and are ignored. To give an example, the following (macOS) commands would read the new value of the Threads parameter from gurobi.env and then optimize model coins.lp using one thread. Note that if the same parameter is changed in both gurobi.env and in your program (or through the Gurobi command-line tool), the value from gurobi.env will be overridden.
> echo "Threads 1" > gurobi.env
> gurobi_cl /Library/gurobi1302/macos_universal2/examples/data/coins.lp
Set parameter Threads to value 1
Read parameters from file gurobi.env
Set parameter LogFile to value "gurobi.log"
Using license file /Users/aramon/gurobi_nu.lic
Using gurobi.env file
Gurobi Optimizer version 13.0.2 build v13.0.2rc1 (mac64[arm] - Darwin 25.5.0 25F80)
Copyright (c) 2026, Gurobi Optimization, LLC
Read LP format model from file /Library/gurobi1302/macos_universal2/examples/data/coins.lp
Reading time = 0.00 seconds
: 4 rows, 9 columns, 16 nonzeros
Using Gurobi shared library /Library/gurobi1302/macos_universal2/lib/libgurobi130.dylib
CPU model: Apple M4 Pro
Thread count: 12 physical cores, 12 logical processors, using up to 1 threads
Non-default parameters:
Threads 1
Optimize a model with 4 rows, 9 columns and 16 nonzeros (Max)
Model fingerprint: 0x06e334a4
Model has 5 linear objective coefficients
Variable types: 4 continuous, 5 integer (0 binary)
Coefficient statistics:
Matrix range [6e-02, 7e+00]
Objective range [1e-02, 1e+00]
Bounds range [5e+01, 1e+03]
RHS range [0e+00, 0e+00]
Found heuristic solution: objective -0.0000000
Presolve removed 1 rows and 5 columns
Presolve time: 0.00s
Presolved: 3 rows, 4 columns, 9 nonzeros
Variable types: 0 continuous, 4 integer (0 binary)
Found heuristic solution: objective 25.2000000
Root relaxation: objective 1.134615e+02, 2 iterations, 0.00 seconds (0.00 work units)
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
0 0 113.46154 0 1 25.20000 113.46154 350% - 0s
H 0 0 112.5000000 113.46154 0.85% - 0s
H 0 0 113.3000000 113.46154 0.14% - 0s
H 0 0 113.3500000 113.46154 0.10% - 0s
H 0 0 113.4500000 113.46154 0.01% - 0s
0 0 113.46154 0 1 113.45000 113.46154 0.01% - 0s
Explored 1 nodes (2 simplex iterations) in 0.00 seconds (0.00 work units)
Thread count was 1 (of 12 available processors)
Solution count 6: 113.45 113.35 113.3 ... -0
Optimal solution found (tolerance 1.00e-04)
Best objective 1.134500000000e+02, best bound 1.134500000000e+02, gap 0.0000%
Note: A few parameters can only be used from the Gurobi command-line tool, and thus can't be set through the API or gurobi.env. These parameters have a note 'Command-line only' in the Parameter Reference of the Gurobi Reference Manual; an example is the parameter ConcurrentSettings.