AI-generated Key Takeaways
-
This guide provides instructions for building OR-Tools from source with Python support on Linux, primarily for users who need to modify the code or use third-party solvers.
-
Before building, you need to install prerequisites like C++ tools, SWIG, and Python 3.8+, along with downloading the desired OR-Tools source code (stable or main branch).
-
You can configure the build using CMake, enabling or disabling support for solvers like SCIP and Gurobi, and build the source code using provided commands.
-
After building, you can test the installation by running examples and install OR-Tools on your system using the installation command, and clean the build files if needed for re-installation.
Introduction
This guide explains how to build from source OR-Tools, with support for Python, on Linux.
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 Linux variants, we have only tested them on machines meeting the following requirements:
- Alpine Edge 64-bit (x86_64)
- Centos 7 LTS 64-bit (x86_64)
- Debian SID 64-bit (x86_64)
- Debian 11 (bullseye) 64-bit (x86_64)
- Fedora 38 64-bit (x86_64)
- Fedora 37 64-bit (x86_64)
- OpenSuse Leap 64-bit (x86_64)
- Ubuntu 24.10 64-bit (x86_64)
- Ubuntu 22.04 LTS 64-bit (x86_64)
- Ubuntu 20.04 LTS 64-bit (x86_64)
Prerequisites
The following sections describe the prerequisites for installing OR-Tools.
C++ tools
To install C++ tools, open a terminal window and enter:
Alpine
apk add alpine-sdk linux-headers cmake lsb-release-minimalCentos
sudo yum groupinstall -y 'Development Tools'sudo yum install -y pkgconfig redhat-lsb-core
Debian
sudo apt updatesudo apt install -y build-essential cmake lsb-release
Fedora
sudo dnf groupinstall -y 'Development Tools'sudo dnf install -y gcc-c++ cmake redhat-lsb-core
Fedora
sudo dnf groupinstall -y 'Development Tools'sudo dnf install -y gcc-c++ cmake redhat-lsb-core
OpenSUSE
sudo zypper refreshsudo zypper install -y git gcc11 gcc11-c++ lsb-release
Ubuntu
sudo apt updatesudo apt install -y build-essential cmake lsb-release
Ubuntu
sudo apt updatesudo apt install -y build-essential cmake lsb-release
Ubuntu
sudo apt updatesudo apt install -y build-essential cmake lsb-release
SWIG
To install SWIG, open a terminal window and enter:
Alpine
apk add swigCentos
sudo yum install -y swigDebian
sudo apt install -y swigFedora
sudo dnf install -y swigFedora
sudo dnf install -y swigOpenSUSE
sudo zypper install -y swigUbuntu
sudo apt install -y swigUbuntu
sudo apt install -y swigUbuntu
sudo apt install -y swigPython
You must have Python 3.8+ installed.
To install Python 3.8+, open a terminal window and enter:
Alpine
apk add python3-dev py3-pip py3-wheelCentos
sudo yum install -y python3 python3-devel python3-pip numpyDebian
sudo apt install -y python3-dev python3-pip python3-venvFedora
sudo dnf install -y python3-devel python3-pip python3-venvFedora
sudo dnf install -y python3-devel python3-pip python3-venvOpenSUSE
sudo zypper install -y python3-devel python3-pip python3-wheelUbuntu
sudo apt install -y python3-dev python3-pip python3-venvUbuntu
sudo apt install -y python3-dev python3-pip python3-venvUbuntu
sudo apt install -y python3-dev python3-pip python3-venvYou can check your Python 3 installation using:
python3 --versionpython3 -c "import platform; print(platform.architecture()[0])"python3 -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 -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 test -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 -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