Python Interface

The Gurobi Python interface can be used in a number of ways. It is the basis of our Interactive Shell, where it is typically used to work with existing models. It can also be used to write standalone programs that create and solve models, in much the same way that you would use our other language interfaces. Finally, our Python interface includes a few higher level constructs that allow you to build models using a more mathematical syntax, similar to the way you might work with a traditional modeling language. We've already introduced the Interactive Shell in an earlier section. This section will work through two examples. The first will present a Python program that is similar to the C, C++, Java, and C# programs presented in previous sections. The second demonstrates some of the higher level modeling capabilities of our Python interface.

This section assumes that you are already familiar with the Python programming language, and that you have read the preceding section on the Gurobi Interactive Shell. If you would like to learn more about the Python language, we recommend that you visit the online Python tutorial.

Note that Gurobi does not require a separate Python installation; the Gurobi distribution includes all tools needed to run Python programs. You will need to use a set of scripts we provide in order to run Gurobi Python programs within the Python environment we distribute. Alternatively, if you are already a Python user, we provide a setup.py script for installing the gurobipy module in your Python environment. You should refer to the instructions for building and running the examples for further details.

Important note for AIX users: due to limited Python support on AIX, our AIX port does not include the Interactive Shell or the Python interface. You can use the C, C++, or Java interfaces.

The Python example directory contains a number of examples. We encourage you to browse and modify them in order to become more familiar with the Gurobi Python interface. We also encourage you to read the Gurobi Example Tour for more information.



Subsections