Using OR-Tools Pip for Python

  • This guide provides instructions for installing and running OR-Tools for Python on various Linux distributions.

  • Users need Python 3.8+ and should follow the provided commands for their specific Linux distribution to install necessary packages.

  • OR-Tools can be installed using pip, and example code can be downloaded from the GitHub repository.

  • After installation, users can run a basic example to confirm their OR-Tools setup.

 Introduction

This guide gets you started with OR-Tools in Python with a simple working example.

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.

Python

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-wheel

Centos

sudo yum install -y python3 python3-devel python3-pip numpy

Debian

sudo apt install -y python3-dev python3-pip python3-venv

Fedora

sudo dnf install -y python3-devel python3-pip python3-venv

Fedora

sudo dnf install -y python3-devel python3-pip python3-venv

OpenSUSE

sudo zypper install -y python3-devel python3-pip python3-wheel

Ubuntu

sudo apt install -y python3-dev python3-pip python3-venv

Ubuntu

sudo apt install -y python3-dev python3-pip python3-venv

Ubuntu

sudo apt install -y python3-dev python3-pip python3-venv

You can check your Python 3 installation using:

python3 --version
python3 -c "import platform; print(platform.architecture()[0])"
python3 -m pip --version

Assuming the prerequisite software is installed on your Linux, take the following steps:

python3 -m pip install -U --user ortools

Or, to install it system wide:

sudo python3 -m pip install -U ortools

Uninstalling OR-Tools

To uninstall OR-Tools, issue the following commands:

python3 -m pip uninstall ortools

Get the Python example code

The example code is located in the python_or-tools repository.

  1. Download the repository as a zip file and extract it, or clone the repository:

    git clone -b v9.12 --depth 1 https://github.com/or-tools/python_or-tools
    
  2. Change to the examples directory:

    cd python_or-tools
    

Run the example

From the python_or-tools directory:

Run the binary using:

python3 basic_example.py

Congratulations! You've just run an application with OR-Tools, you are ready to get started with OR-Tools.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-03-18 UTC.