Gurobi Installation

The following manual will guide you through the installation of the optimization software Gurobi, using Python (in version 3.11) as an interface. We will write our optimization models in Python code and then pass the model to Gurobi to solve it. The manual also explains how to install Gurobi and afterwards multiple Solutions to install Python. With this software you can, for instance, solve linear and integer linear programs, which you know from the lecture. We recommend to use an IDE of your choice.

A detailed manual and additional examples can be found in the quickstart guides for the corresponding operating systems:

1. Installing Gurobi

In order to use gurobi, a license is required. As a student, the license can be obtained for free here (you need a "Named-User Academic" license). When creating an account, select "Academic" and specify your RWTH mail address. Make sure that the mail address is spelled correctly.

Here, the current Gurobi version for the corresponding operating system can be obtained. Finally, Gurobi should be installed.

Select the license, copy (as shown below) the grbgetkey-command, and execute it in the console. Under Windows, open the start menu and search for cmd.exe in the search field. Under Mac or Linux, open a terminal.

The output should look like the following:

$ grbgetkey 6b085692-feba-11e8-83af-02e454ff9c50
info : grbgetkey version 8.1.0, build v8.1.0rc1
info : Contacting Gurobi key server...
info : Key for license ID 288374 was successfully retrieved
info : License expires at the end of the day on 2019-12-13
info : Saving license key...

In which directory would you like to store the Gurobi license key file?
[hit Enter to store it in /home/fibis]:

info : License 288374 written to file /home/fibis/gurobi.lic

2. Installing Python

Now you can download here Python for your operation system. Please make sure that the downloaded version is exactly 3.11. Now install Python via the downloaded package. Select "Add Python 3.X to PATH" during the installation.

To test if the installation was successful, you can run the command python -V in your terminal. This will return the installed Python version. If your operating system didn't recognize the python command, you have to reinstall Python and make sure that the option "Add Python 3.X to PATH" is checked.

Now you have to install the Gurobi-Python package. To do this, open a terminal and execute python -m pip install gurobipy.

Optional, highly recommended

To enable type hints, autocomplete and linting for Gurobi (if you dont' know what these are, you definitly will profit from having them), you will need to also run the following command in the terminal (only works for Gurobi versions 9.5 and higher): python -m pip install gurobipy-stubs

3. Installing IDE

We recommend you to edit the code and solve the tasks with an IDE, as this makes many things easier. We will guide you through the installation and configuration of Visual Studio Code. You can also use a development environment of your choice.

Download here Visual Studio code for your operating system and follow the installation instructions. Also download the file diet.py.
Open Visual Studio Code and open the diet.py file. Visual Studio Code will directly suggest you to install the Python extension. Confirm this.

After the installation is complete, you must select the correct Python interpreter. Follow this guide. to achieve this. If you have chosen the interpreter, you can start.

At the top right you will find the play symbol . Press it to execute your code. The Terminal will open and execute the code. You will directly see the output or any errors. The output should look like this:

/usr/bin/python3 "diet.py
Academic license - for non-commercial use only
Optimize a model with 3 rows, 4 columns and 12 nonzeros
Coefficient statistics:
Matrix range [3e-01, 6e+02]
Objective range [7e-02, 8e-01]
Bounds range [0e+00, 0e+00]
RHS range [2e+01, 2e+03]
Presolve time: 0.00s
Presolved: 3 rows, 4 columns, 12 nonzeros

Iteration Objective Primal Inf. Dual Inf. Time
0 0.0000000e+00 6.250000e+01 0.000000e+00 0s
3 4.1055830e+00 0.000000e+00 0.000000e+00 0s

Solved in 3 iterations and 0.00 seconds
Optimal objective 4.105583027e+00
eat 4.501006178644742 units of apple
eat 0.18808967630373452 units of peanutbutter
eat 0.0 units of milk
eat 8.813922680985751 units of bread
Total cost: 4.1055830274348

Optional: configure Pylint

If Pylint has been installed, it is possible that a message will appear saying that the Gurobi commands cannot be found. The following steps solve this problem:

Happy coding!

Common errors

No such file or directory / "Der Systempfad kann nicht gefunden werden, da er nicht vorhanden ist."
If you get this message when trying to navigate to the gurobi folder in the terminal (e.g. with cd /Library/gurobi951/mac64), then the corresponding folder does not exist. Solutions:


command not found: python
If you get this error, Python has not been added to your environment variables. To fix this, please redo step 2 and be sure to set the check mark to "Add Python 3.X to PATH". If the error still appears, it may be that the Python-path is in the wrong position in the list of environment variables. Find the list of environment variables in the windows settings and change the order such that the Python path is at the top of the list.
If you get this error message and the additional information that something has to be deactivated in the Microsoft Store: Search for "Manage app execution aliases" in the windows search bar and click on it. Then scroll down to the bottom of the list and deactivate the two entries "App Installer - python.exe" and "App Installer - python3.exe". Afterwards, uninstall Python and reinstall it, making sure to set the check mark to "Add Python 3.X to PATH".
No module named gurobipy
The problem is a missing setup of Gurobi in the used Python-Version. Possible solutions:
Errors regarding missing permissions when using python/python3
Problem: The used python command is wrong. Solutions:
Visual Studio Code does not show a "play button" too execute Python files
You need to install the Python Extension for Visual Studio Code.
Clicking on the "play button" does nothing Possibly your VSC is in "protected mode". In this case you have to press "trust workspace" in the bottom left.

If you should get any errors, please do not hesitate to contact the responsible e-mail address of your lecture.