AI-generated Key Takeaways
-
This guide provides instructions for building OR-Tools from source with Python support on Windows 10 64-bit using Visual Studio 2022 and requires prerequisites like Git, CMake, and Python.
-
To build OR-Tools, download the source code from GitHub, configure the build with CMake, and compile it using specified commands in a terminal.
-
You can test the installation by running examples and clean the build files using the provided commands if needed for re-installation.
-
OR-Tools supports optional third-party solvers like SCIP, Gurobi, CPLEX, GLPK, and XPRESS, and you can install OR-Tools for Python on your system using the installation command.
-
Although package installation is recommended for most users, building from source is necessary for modifying source code or utilizing third-party solvers with OR-Tools.
Introduction
This guide explains how to build from source OR-Tools, with support for Python, on Windows.
Unless you plan to modify the source code or use a third-party solver with OR-Tools, we recommend the package installation.
Although these instructions might also work on other Windows variants, we have only tested them on machines meeting the following requirements:
Windows 10 64-bit (x86_64) with:
- Microsoft Visual Studio Enterprise 2022
- Microsoft Visual Studio Community 2022 Preview 2 or above
Prerequisites
The following sections describe the prerequisites for installing OR-Tools.
Visual Studio
To build and run OR-Tools on Windows, you must have Visual Studio 2022 or later installed on your computer with the C++ toolset for Visual Studio.
You can find more details here.
To build OR-Tools programs from the command line you must use a x64 Native Tools Command Prompt (not the Developer Command Prompt).
You can find more details here.
Git
Git, which can be downloaded from https://git-scm.com/.
CMake
CMake (>= 3.18), which can be downloaded from https://www.cmake.org/download. When installing CMake, select the option for a command-line accessible cmake.
Python
You must have one of the following versions of Python installed:
Then verify that you have pip 9.01 or higher available in your PATH:
python --versionpython -c "import platform; print(platform.architecture()[0])"python -m pip --version
Download the source code
There are two distinct branches of the OR-Tools source code on
GitHub: stable and main.
The stable branch has been thoroughly tested and should work flawlessly on all
supported platforms.
The main branch is where the latest updates and
improvements have been applied; it's more current, but less stable.
Download the stable source code
You can get the stable source code for OR-Tools in either of the following ways:
Clone the
stablebranch by entering:git clone https://github.com/google/or-toolsDownload the latest release in a compressed file, by clicking the
Clone or downloadbutton in GitHub.
Download the main source code
To retrieve the source code from the main branch, enter:
git clone -b main https://github.com/google/or-toolsDownload previous releases
You can get the source code for previous releases in either of the following ways:
- Download a previous release from the GitHub release page.
Assuming you have already created a local repository (by
git clone), you can check out a specific release using a Git tag. For example, to work with the v9.12 release instead of themainbranch, enter the following commands in your local repo:git fetch --all --tags --prunegit checkout tags/v9.12 -b v9.12
Configure the build
Before building OR-Tools, you'll need to configure the CMake build system generator.
Open a terminal and navigate to the directory where you extracted the files. Then enter:
cmake -S . -B build -DBUILD_DEPS=ON -DBUILD_PYTHON=ONCheckout the CMake documentation for details.
Using SCIP
Since v7.8, SCIP is now integrated so you won't have to install it manually.
Using Gurobi
Gurobi is now pre-integrated. When needed, at runtime, OR-Tools will search for
the Gurobi shared library in the default install path of the Gurobi installers
on MAC OS X and Windows, or by using the GUROBI_HOME environment variable.
Using an optional third-party MIP solver
You can also use OR-Tools with any of the following optional third-party MIP solvers whose support is disabled by default:
- CPLEX
- GLPK (Linux and MacOS only)
- XPRESS Solver
Please take a look at this documentation for details.
Build the source code
To build the source code, open a terminal and navigate to the directory where you extracted the files. Then enter the following command to compile OR-Tools:
cmake --build build --config Release --target ALL_BUILD -j -vCheckout the CMake documentation for details.
Test the source code
You can check that everything is running correctly by entering:
cmake --build build --config Release --target RUN_TESTS -vThis runs examples for OR-Tools. If all the examples run successfully, you are ready to get started with OR-Tools.
Cleaning the build files
If you need to re-install OR-Tools, the command:
rm -r buildwill remove all compiled dependencies. This can be useful for resetting to a clean state.
Then re-enter the commands:
cmake -S . -B build -DBUILD_DEPS=ON -DBUILD_PYTHON=ON
cmake --build build --config Release --target ALL_BUILD -j -vInstalling OR-Tools on your operating system
You can install OR-Tools for Python on your operating system by entering:
cmake --build build --config Release --target INSTALL -v