Installing OR-Tools from 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 Linux or Mac OS X

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

  1. Install prerequisite software
  2. Download the source code
  3. Build the source code
  4. Install third-party solvers
  5. Test the installation

1. Install prerequisite software

To install OR-Tools from source on Linux or Mac OS X, you must first install CMake version 3. You can download a version for your operating system on the CMake download page. (We recommend installing from the .sh file, not the .tar.gz.) If you're on Linux Ubuntu >= 16.04, install with sudo apt-get install cmake.

Additional requirements specific to Linux and Mac OS X are described below.

  • Linux

    The packages to install depend on which languages you'll be using. Choose any of the following that apply:

    • To use OR-Tools from C++:
      sudo apt-get -y install git autoconf libtool zlib1g-dev gawk g++ curl cmake subversion make lsb-release
    • To use OR-Tools from any other language:
      sudo apt-get -y install swig
    • To use OR-Tools from Python 2:
      sudo apt-get -y install python-dev python-setuptools python-six
    • To use OR-Tools from Python 3:
      sudo apt-get -y install python3-dev python3-setuptools python-six
    • To use OR-Tools from Java:
      sudo apt-get -y install default-jdk
    • To use OR-Tools from C#:
      sudo apt-get -y install mono-complete
    (If your platform uses a package management system other than apt-get, use the appropriate command for your system.)

    If you plan to use Python and you installed Python via a package management system, make sure the corresponding "python-dev" package is also installed. This includes the Python header file (Python.h), which is required to build Python C extensions.

  • Mac OS X

    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

You can also clone the OR-Tools repository on GitHub if you wish.

To use OR-Tools with C#, you must install Mono version 4.2.0 or later. You can download the latest version of Mono from the Mono Download page.

2. Download the source code

You have a couple of options for the source code to install:

  • The latest release — tar.gz or zip

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

  • The source code in the OR-Tools repository on GitHub

    These are the latest versions of the files under development. Note that this code may not be fully tested on all platforms.

Previous releases are available from the binary and source archives.

3. Build the source code

First, open a terminal and navigate to the directory where you extracted the files. Then enter the following command:

make third_party

Then, select one of the options below:

  • To install C++ only:
    make cc
  • To install both C++ and Python:
    make python
  • To install both C++ and Java:
    make java
  • To install C++ and C#, enter
    make csharp
  • To install all of C++, Python, Java, and C#:
    make all

4. 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. On Linux, enter:
     make GMP=false READLINE=false TPI=tny USRCFLAGS=-fPIC \
     USRCXXFLAGS=-fPIC USRCPPFLAGS=-fPIC
    	
    On Mac OS X, enter:
    make GMP=false READLINE=false TPI=tny
  4. Change to the directory where you extracted the OR-Tools archive.
  5. Edit Makefile.local by adding the line:
    UNIX_SCIP_DIR=<path to sciptopsuite-4.0.1>/scip-4.0.1
  6. Enter the following command:
    make clean && make cc

To test the installation, enter the following command to solve an integer programming problem using SCIP:

bin/integer_programming
5. Test the installation

You can check that everything is running correctly by entering:

make test

This runs a selection of examples in C++, Python, Java, and C#. If the examples run successfully, you're all set to start running OR-Tools programs.

Cleaning the installation files

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

make clean_third_party

will remove 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.

Installing on Windows

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

  1. Install prerequisite software
  2. Download the source code
  3. Build the source code
  4. Install third-party solvers
  5. Test the installation
1. 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.
2. Download the source code

You have a couple of options for the source code to install:

  • The latest release — tar.gz or zip

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

  • The source code in the OR-Tools repository on GitHub

    These are the latest versions of the files under development. Note that this code may not be fully tested on all platforms.

Previous releases are available from the binary and source archives.

3. Build the source code

To build from source:

  1. Download the archive for the source code, or clone the OR-Tools repository on GitHub.
  2. Add the tools subdirectory of the installation directory to the Windows PATH environment variable.
  3. Open the Visual Studio Native Tools Command Prompt and navigate to the installation directory.
  4. Enter the following command:
    tools\make third_party
  5. 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. 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.
  6. Change to the directory where you extracted OR-Tools.
  7. Edit the file Makefile.local by adding the line
    WINDOWS_SCIP_DIR=<path to scip-4.0.1>
  8. Enter the following commands:
    tools\make clean
    tools\make cc

To test the installation, enter the following command to solve an integer programming problem using SCIP:

bin\integer_programming
5. Test the installation

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#. If the examples run successfully, you are all set to start running OR-Tools programs.

Cleaning the installation 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 only necessary 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.

Another common error is using pip, which pulls the wrong archive with a wrong platform. Use easy_install, or better yet, the installation instructions in the OR-Tools Python distribution.

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