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 the 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 tools for installing the gurobipy module in your Python environment. You should refer to the instructions for building and running the examples for further details.

One big advantage of working within Python is that the Python language is popular and well supported. One aspect of this support is the breadth of powerful Python Integrated Development Environments (IDEs) that are available, most of which can be downloaded for free from the internet. This document includes instructions for setting up Gurobi for use within the PyScripter IDE for Windows. In our opinion, PyScripter strikes a nice balance between power and simplicity. If you are a Windows user and would prefer to use a graphical environment over a more command-line driven environment, we suggest that you install PyScripter now. You can also consult the PyScripter instructions for pointers to other IDE options that might be of interest if you are on a different platform or would like to try a different Windows Python IDE.

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

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.

Search