Using OR-Tools Pip for Python

  • This guide provides instructions for installing and running OR-Tools, a powerful optimization library, specifically on MacOS with Python 3.8+.

  • Before installing OR-Tools, ensure you have Homebrew and Python 3.8+ installed on your system, following the provided commands for installation and verification.

  • Install OR-Tools using pip, either for your user or system-wide, and download the example code from the GitHub repository to get started.

  • Run the provided "basic_example.py" file using Python 3 to verify your installation and explore a basic application of OR-Tools.

  • Once you've completed these steps, you'll be ready to delve deeper into OR-Tools and utilize its capabilities for optimization tasks.

 Introduction

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

Although these instructions might also work on other MacOS variants, we have only tested them on machines meeting the following requirements:

  • MacOS 13.0.1 (Ventura) Intel 64-bit (x86_64)
  • MacOS 13.0.1 (Ventura) M1 (arm64)

Prerequisites

The following sections describe the prerequisites for installing OR-Tools.

Homebrew

To install the remaining prerequisites, we recommend first installing the "missing package manager for macOS" otherwise known as Homebrew. To do so, open a terminal window and enter:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew update

To verify that you’ve successfully installed brew:

brew --version

You should see:

Homebrew 1.6.9-8-g25542d7
Homebrew/homebrew-core (git revision 0e0c84; last commit 2018-06-20)

Python

You must have Python 3.8+ installed.

To install Python 3.8+, open a terminal window and enter:

brew install python
python3 -m pip install -U --user wheel six

Then verify your installation:

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

Assuming the prerequisite software is installed on your MacOS, 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.