Joel Andersson edited this page Nov 14, 2015 · 67 revisions

Installation on Mac OS X from sources

Note that CasADi is now available as binary installers for Mac, see the installation instructions. The instructions below apply to the installation of CasADi from sources.

Start out by installing all the dependencies using a package handler. We strongly recommend you to use Homebrew, as described below. There are also legacy instructions available on how to get the dependencies you need via Macports, but we don't recommend this option.

Getting the dependencies via Homebrew (recommended option)

Homebrew is a package manager for Mac that greatly simplifies the installation of open source software. It is similar to Macports (below), but avoids many of its problems, e.g. by installing in a standard location (typically /usr/local) and by using the system compiler and system Python installation. Instructions:

  • Install Homebrew as described on the website. At the end of installation, run brew doctor and resolve any issues appearing.
  • "Tap" homebrew science to be able to install packages such as cmake:
    • brew tap homebrew/science
  • Brew at least the following:
    • brew install wget swig gcc cmake pkg-config
  • Other useful development tools:
  • Run brew doctor to make sure that your installation was successful and if there are some name conflicts that need to be resolved.
  • If you plan to use CasADi from Python (recommended), you need a Python environment with some standard numerical packages. For this you can either use the Python that is distributed with OS X or obtain a Python using homebrew. The Homebrew Python comes with the pip package manager, otherwise you have to install it separately. Use of other Python distributions (e.g. downloaded from the Python website) is strongly discouraged.
    • Option 1 (Recommended but with a caveat): Use Python from Homebrew. This will guarantee a recent Python installation and comes with "pip". To install, simply do brew install python. The caveat is that you will have two Python installations on your system, since your Mac has Python pre-installed, and this can result in conflicts. Make sure that the Homebrew Python appears first in your paths.
    • Option 2 (Use system Python): Macs come with Python preinstalled, but it is unfortunately often not an up-to-date version with the latest bug fixes, hence the recommendation to use Homebrew Python above. It also does not come with "pip", so you will have to install that yourself, for example by issuing easy_install pip.
  • (Python) Obtain ipython (interactive Python shell) as well as the Python packages matplotlib, numpy and scipy from pip:
    • pip install ipython matplotlib numpy scipy

Interactive development environment

One of the main benefits of using Python is the ability to work interactively. To do this efficiently, we recommend you to obtain an interactive Python environment such as the Ipython Notebook or Spyder. You will find the installation instructions below.

Option 1: Ipython Notebook

The Ipython Notebook gives a convenient way to interact with Python by writing notebooks, similar to what you may be used from e.g. Maple or Mathematica. You obtain it from pip:

  • pip install pyzmq jinja2 tornado ipython[notebook]

Option 2: Spyder

Spyder gives you a MATLAB-like development environment for Python. We recommend you to obtain it from pip and not download it from the Spyder website:

  • pip install sphinx spyder

If you try to launch Spyder (e.g. by issuing ´spyder´ from the command line), you will probably get an error message telling you to install PyQt4. This can be done as follows:

  • brew install pyqt
  • brew linkapps

Pay attention to the warning messages. You might need to modify your Python paths to get everything working.

Installing IPOPT (recommended if you plan to solve optimal control problems)

IPOPT can either be obtained from a package manager, downloaded as a binary or compiled from sources. On OS X, we recommend you to obtain IPOPT from Homebrew:

  • brew install ipopt --with-openblas (go for a long coffee break)

If you wish to build IPOPT from sources, just follow the instructions for Linux.

After IPOPT has been installed, you might want to install additional linear solvers. For more information on this, check IPOPT's webpage or the following instructions for obtaining HSL.

Compiling CasADi

With the dependencies in place, compile CasADi from sources. We strongly recommend you to use clang/clang++ as the C/C++ compiler, which is the default compiler on newer OS X.

Go to some a directory of choice and checkout CasADi from Github. We recommend you to get the "master" branch, which contains the latest release (for information about other branches, see the installation instructions for Linux):

  • cd ~/src (or any other directory where you want to keep your sources)
  • git clone -b master casadi

Configure and build. We recommend you to install everything locally, for example to $HOME/local as follows:

cd casadi; mkdir build; cd build
cmake \
  -D PYTHON_LIBRARY:FILEPATH=`python-config --prefix`/lib/libpython2.7.dylib \
  -D PYTHON_EXECUTABLE:FILEPATH=`python-config --prefix`/bin/python \
  -D PYTHON_INCLUDE_DIR:PATH=`python-config --prefix`/include/python2.7 ..

Have a look at the generated CMakeCache.txt file. Make sure that the paths involving Python are consistent, in particular PYTHON_EXECUTABLE, PYTHON_LIBRARY and PYTHON_INCLUDE_DIR. If you've installed locally, make sure that the libraries can be found by adding following lines (modify if your installation location was different from ~/local) to your ~/.profile or ~/.bash_profile file:


Compile and run the test suite to make sure that the installation was successful:

make install
cd ../test/python

Cf. also the installation instructions for Linux.