Installing OR-Tools (source)

The sections below will guide you through the OR-Tools source code installation on Linux, Mac OS X, and Windows. Unless you have a specific need for the source code, we recommend the binary installation.

Google created OR-Tools in C++, but you can also use it with Python, C#, or Java.
Internally, we run it on Linux, but you can also install it on Windows and Mac OS X.

The source code for OR-Tools is available on GitHub.

Installing on GNU/Linux

The following section explains the steps for installing OR-Tools from source on GNU/Linux:

  1. Install prerequisite software
  2. Optional: Install third-party solvers
  3. Download the source code
  4. Build the source code
  5. Optional: Install OR-Tools

Install prerequisite software

If you are on Trusty (Ubuntu 14.04LTS), replace cmake with cmake3 in the command lines below.

The packages to install depend on which languages you'll be using:

  • To use OR-Tools from C++:
    sudo apt-get -y install git wget build-essential cmake autoconf libtool zlib1g-dev lsb-release
  • To use OR-Tools from Python 2:
    sudo apt-get -y install git wget build-essential cmake autoconf libtool zlib1g-dev lsb-release swig pkg-config python-dev python-setuptools python-wheel python-six
  • To use OR-Tools from Python 3:
    sudo apt-get -y install git wget build-essential cmake autoconf libtool zlib1g-dev lsb-release swig pkg-config python3-dev python3-setuptools python3-wheel python3-six
  • To use OR-Tools from Java:
    sudo apt-get -y install git wget build-essential cmake autoconf libtool zlib1g-dev lsb-release swig default-jdk
  • To use OR-Tools from C#:
    sudo apt-get -y install git wget build-essential cmake autoconf libtool zlib1g-dev lsb-release swig mono-complete

Optional: Install third-party solvers

If you anticipate needing to solve mixed-integer programs, you may want to install the open-source third-party solver SCIP:

  1. Download and unpack SCIP Optimization Suite 4.0.1.
  2. Open a terminal and navigate to the directory where you extracted the tar file.
  3. Then build it:
    make GMP=false READLINE=false TPI=tny USRCFLAGS=-fPIC USRCXXFLAGS=-fPIC USRCPPFLAGS=-fPIC

Download the source code

You have a couple of options to get the source code of OR-Tools:

  • Donwload the latest release as:
    • a tar.gz archive or;
      wget "https://github.com/google/or-tools/archive/v6.7.2.tar.gz"
    • a zip archive.
      wget "https://github.com/google/or-tools/archive/v6.7.2.zip"

    The release is a stable version of OR-Tools that has been fully tested on all the supported platforms. This is the best option unless you want to try out experimental features.

  • Clone the latest OR-Tools repository from GitHub

    This is the latest version of OR-Tools source code integrating all features (even under development).
    For example, to clone the master, issue the following command:

    git clone https://github.com/google/or-tools

To get previous releases you have the same couple of options:

  • Download previous release from the GitHub release page.
  • Checkout to a specific time point in the revision history using a git tag.

    For example to work with the v6.7 release instead of the master, issue the following command in your local repository:

    git fetch --all --tags --prune
    git checkout tags/v6.7 -b v6.7

Build the source code

  1. First, open a terminal and navigate to the directory where you extracted the files. Then enter the following command:
    make third_party
  2. If you have installed third party solver, please edit Makefile.local.
    For example for SCIP you add something like this:
    UNIX_SCIP_DIR=<path to sciptopsuite-4.0.1>/scip-4.0.1
  3. Then, select one of the options below:
    • To build C++ only:
      make cc
    • To build both C++ and Python:
      make python
    • To build both C++ and Java:
      make java
    • To build C++ and C#:
      make csharp
    • To build all of C++, Python, Java, and C#:
      make all
  4. To test the third party solver installation, enter the following command to solve an integer programming problem using SCIP:
    bin/integer_programming
  5. You can check that everything is running correctly by entering:
    make test

    This runs a selection of examples in C++, Python, Java, and C#.

Optional: Install OR-Tools

Currently, we don't provide a way to install OR-Tools for Java and C#.
To run examples from the command line, you must add bin directory to your PATH and add lib to your LD_LIBRARY_PATH.

To use OR-Tools in your project, select one of the options below:

  • To install the C++ OR-Tools library:
    make install_cc
  • To install the Python OR-Tools package:
    make install_python
  • For Java, use the jar in lib/com.google.ortools.jar and add ‑Djava.library.path=PATH_TO_or‑tools/lib to your command line.
  • For C#, add bin/Google.OrTools.dll to your project dependencies.

Installing on Mac OS X

The following section explains the steps for installing OR-Tools from source on Mac OS X:

  1. Install prerequisite software
  2. Optional: Install third-party solvers
  3. Download the source code
  4. Build the source code
  5. Optional: Install OR-Tools

Install prerequisites software

First, install Xcode Command Line Tools, which includes git. (The full Xcode distribution isn't necessary.)
To install the tools, open the Terminal, found in /Applications/Utilities/, and enter:

xcode-select --install

Then you have a bunch of open source tools to install. We recommend installing them using the "missing package manager for macOS" aka Homebrew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
  • To use OR-Tools from C++:
    brew install cmake wget
  • To use OR-Tools from Python 2:
    brew install cmake wget swig pkg-config python@2
    python2 -m pip install wheel six
    
  • To use OR-Tools from Python 3:
    brew install cmake wget swig pkg-config python
    python -m pip install wheel six
    
  • To use OR-Tools from Java:
    brew cask install java
    brew install cmake wget swig maven
    
  • To use OR-Tools from C#:
    brew install cmake wget swig mono nuget

Optional: Install third-party solvers

If you anticipate needing to solve mixed-integer programs, you may want to install the open-source third-party solver SCIP:

  1. Download and unpack SCIP Optimization Suite 4.0.1.
  2. Open a terminal and navigate to the directory where you extracted the tar file.
  3. Then build it:
    make GMP=false READLINE=false TPI=tny

Download the source code

You have a couple of options to get the source code of OR-Tools:

  • Donwload the latest release as:
    • a tar.gz archive or;
      wget "https://github.com/google/or-tools/archive/v6.7.2.tar.gz"
    • a zip archive.
      wget "https://github.com/google/or-tools/archive/v6.7.2.zip"

    The release is a stable version of OR-Tools that has been fully tested on all the supported platforms. This is the best option unless you want to try out experimental features.

  • Clone the latest OR-Tools repository from GitHub

    This is the latest version of OR-Tools source code integrating all features (even under development).
    For example, to clone the master, issue the following command:

    git clone https://github.com/google/or-tools

To get previous releases you have the same couple of options:

  • Download previous release from the GitHub release page.
  • Checkout to a specific time point in the revision history using a git tag.

    For example to work with the v6.7 release instead of the master, issue the following command in your local repository:

    git fetch --all --tags --prune
    git checkout tags/v6.7 -b v6.7

Build the source code

  1. First, open a terminal and navigate to the directory where you extracted the files. Then enter the following command:
    make third_party
  2. If you have installed third party solver, please edit Makefile.local.
    For example for SCIP you add something like this:
    UNIX_SCIP_DIR=<path to sciptopsuite-4.0.1>/scip-4.0.1
  3. Then, select one of the options below:
    • To build C++ only:
      make cc
    • To build both C++ and Python:
      make python
    • To build both C++ and Java:
      make java
    • To build C++ and C#:
      make csharp
    • To build all of C++, Python, Java, and C#:
      make all
  4. To test the third party solver installation, enter the following command to solve an integer programming problem using SCIP:
    bin/integer_programming
  5. You can check that everything is running correctly by entering:
    make test

    This runs a selection of examples in C++, Python, Java, and C#.

Optional: Install OR-Tools

Currently, we don't provide a way to install OR-Tools for Java and C#.
To run examples from the command line, you must add bin directory to your PATH and add lib to your DYLD_LIBRARY_PATH.

To use OR-Tools in your project, select one of the options below:

  • To install the C++ OR-Tools library:
    make install_cc
  • To install the Python OR-Tools package:
    make install_python
  • For Java, use the jar in lib/com.google.ortools.jar and add ‑Djava.library.path=PATH_TO_or‑tools/lib to your command line.
  • For C#, add bin/Google.OrTools.dll to your project dependencies.

Installing on Windows

The following section explains the steps for installing OR-Tools from source on Windows:

  1. Install prerequisites
  2. Optional: Install third-party solvers
  3. Download the source code
  4. Build the source code
  5. Optional: Install OR-Tools

Install prerequisite software

The following software must be installed on your computer before you can install OR-Tools from source on Windows:

  • Visual Studio 2015 or later
  • Git, which can be downloaded from https://git-scm.com/.
  • SVN (Any version that provides svn.exe will do.)
  • CMake 3: download the official .dmg archive from https://www.cmake.org/download. When installing CMake, select the option for a command-line accessible cmake.

Optional: Install third-party solvers

If you anticipate needing to solve mixed-integer programs, you may want to install the open-source third-party solver SCIP:

  1. Download the following files and unpack them:
  2. Open a command window and create this directory:
    md scip-4.0.1
  3. Copy the include directory from the scipoptheaders archive to scip-4.0.1.
  4. Copy the file libscipopt.lib from the SCIP compiled library to scip-4.0.1.
  5. Copy the .dll file at the top level of the SCIP compiled library to any directory on the Windows PATH.

Download the source code

You have a couple of options to get the source code of OR-Tools:

  • Donwload the latest release as:
    • a tar.gz archive or;
      wget "https://github.com/google/or-tools/archive/v6.7.2.tar.gz"
    • a zip archive.
      wget "https://github.com/google/or-tools/archive/v6.7.2.zip"

    The release is a stable version of OR-Tools that has been fully tested on all the supported platforms. This is the best option unless you want to try out experimental features.

  • Clone the latest OR-Tools repository from GitHub

    This is the latest version of OR-Tools source code integrating all features (even under development).
    For example, to clone the master, issue the following command:

    git clone https://github.com/google/or-tools

To get previous releases you have the same couple of options:

  • Download previous release from the GitHub release page.
  • Checkout to a specific time point in the revision history using a git tag.

    For example to work with the v6.7 release instead of the master, issue the following command in your local repository:

    git fetch --all --tags --prune
    git checkout tags/v6.7 -b v6.7

Build the source code

  1. First, open the Visual Studio Native Tools Command Prompt and navigate to the directory where you extracted the files. Then enter the following command:
    tools\make third_party
  2. If you have installed a third party solver, please edit Makefile.local.
    For example for SCIP, you'd add something like this:
    WINDOWS_SCIP_DIR=<path to scip-4.0.1>
  3. Select one of the options below:
    • To build the C++ libraries and examples:
      tools\make cc
    • To build for both Python and C++:
      tools\make python
    • To build for both Java and C++:
      tools\make java
    • To build for both C# and C++:
      tools\make csharp
    • To build everything:
      tools\make all
      .
  4. To test the third party solver installation, enter the following command to solve an integer programming problem using SCIP:
    bin\integer_programming
  5. You can check that everything is running correctly by entering:
    tools\make test

    This runs a selection of examples in C++, Python, Java, and C#.

Optional: Install OR-Tools

Currently, we don't provide a way to install OR-Tools for Java and C#.
To run examples from the command line, you must add bin directory to your PATH and add lib to your PATH.

To use OR-Tools in your project, select one of the options below:

  • To install the C++ OR-Tools library:
    make install_cc
  • To install the Python OR-Tools package:
    make install_python
  • For Java, use the jar in lib/com.google.ortools.jar and add ‑Djava.library.path=PATH_TO_or‑tools/lib to your command line.
  • For C#, add bin/Google.OrTools.dll to your project dependencies.

Cleaning the build files

If you need to re-install OR-Tools, the command:

tools\make clean_third_party

will remove all compiled dependencies and Makefile.local. This can be useful for resetting to a clean state, or if you have added an archive to dependencies/archives.

Troubleshooting

The following section describes some possible solutions in case you encounter problems installing OR-Tools, whether from source or binary:

General troubleshooting

Could not find suitable distribution for ortools
Here's a sample error message:
  • On Unix: No local packages or download links found for ortools>=SOME_VERSION
    error: Could not find suitable distribution for Requirement.parse('ortools>=SOME_VERSION')
    .
  • On Windows: Could not load file or assembly 'Google.OrTools, Version=SOME_VERSION, Culture=neutral, PublicKeyToken=null'.
This occurs when you try to install a binary distribution, but the installer is unable to build the ortools package for your operating system. In this case, you can still install and run OR-Tools from source files, and even build the python package yourself. You can do so, by following these steps:
Can't open y.tab.[ch] or bison: No such file or directory

Sometimes Bison, a parser generator, will fail to build. Bison is necessary only for FlatZinc, a solver input language used for the MiniZinc constraint modeling language. If you don't have an explicit need for those, comment out the install bison line in makefiles/Makefile.third_party.unix and rebuild.

make install_python_module didn't succeed

If you're on OpenSuse (and possibly Red Hat), make install_python_module will fail. One workaround is described on this page: http://stackoverflow.com/questions/4495120/ combine-user-with-prefix-error-with-setup-py-install.

Cannot download pcre

Here's a sample error message:

svn co svn://vcs.exim.org/pcre/code/trunk -r 1336 dependencies/sources/pcre-1336 svn: E000101: Unable to connect to a repository at URL 'svn://vcs.exim.org/pcre/code/trunk' svn: E000101: Can't connect to host 'vcs.exim.org': Network is unreachable make: [dependencies/sources/pcre-1336/autogen.sh] Error 1

Unfortunately, the pcre servers are flaky. Just retry until it works.

Missing gflags.h

Sample error message:

src\base/commandlineflags.h(17) : fatal error C1083: Cannot open include file: 'gflags/gflags.h': No such file or directory tools\make: [objs/alldiff_cst.obj] Error 2

This means that make third_party didn't succeed, or wasn't run.

Error C2143

You're using Visual Studio 2010 and will need to upgrade to a later version (2013 or afterward).

[dependencies/install/lib/protobuf.jar] Error 1

Sample error message:

The system cannot find the path specified
make: *** [dependencies/install/lib/protobuf.jar] Error 1

You need to set the variable WINDOWS_JDK_DIR with the path to your JDK in Makefile.local.
Remember to set the variables WINDOWS_PYTHON_VERSION and WINDOWS_PYTHON_PATH to use python.

'Python.h' file not found

If this error occurs when you run make all or make python, it means that make was unable to find Python's lib or include directories. To specify where make can find them, use the ADD_PYTHON_INC environment variable like so:

make python ADD_PYTHON_INC="-I/PATH/TO/PYTHON/lib -I/PATH/TO/PYTHON/include/pythonVERSION"

Unrecognized visual studio version
This is a Windows-specific error, and it means that the VisualStudioVersion variable is not set in your terminal. If you're using a generic Windows terminal, use a Visual Studio terminal instead. If you're already using a Visual Studio terminal, then set VisualStudioVersion to your version of Visual Studio:
  • For VS2017, set VisualStudioVersion=15.0
  • For VS2015, set VisualStudioVersion=14.0

Troubleshooting an installation with Python support

Permission denied: '/Library/Python/.../EGG-INFO/namespace_packages.txt

If you see this error when trying to run one of the Python examples after having followed the instructions above, you probably installed with sudo python setup.py install instead of python setup.py install --user. You can run the examples with sudo, e.g., sudo python examples/golomb8.py.

ImportError: No module named pywraplp

Most likely, you're using Windows XP. Unfortunately, OR-Tools requires Visual Studio 2013 or higher, which is incompatible with Windows XP.

ImportError: Cannot import name

Most likely, you don't have the right versions of the ortools or protobuf modules. To check whether this is the case, run the following command:

make third_party_check

If this returns a message saying that your versions of Python or the protobuf modules are different from required versions (or that they are not installed), you need to reinstall OR-Tools as follows:

make install
Other errors

If you see errors when installing the Python build of OR-Tools, you can try upgrading setuptools using the instructions found here.

If you still have problems, especially on Mac OS X, here is a workaround found by a user:

  • Upgrade setuptools from 12.05 to 12.1 by running
    curl https://bootstrap.pypa.io/ez_setup.py -o - | python
  • Run
    pip install ez_setup
  • Install OR-Tools by running
    pip install ortools

Send feedback about...

Optimization
Optimization