Skip to content


jgillis edited this page May 21, 2018 · 261 revisions
Clone this wiki locally

Installing CasADi

Option 1: Binary installation (recommended)

Install CasADi 3.4.4

For Python users: pip install casadi (you must have pip --version >= 8.1!)

Grab a binary from the table (for MATLAB, use the newest compatible version below):

Windows Linux Mac
Matlab R2014b or later,
R2013a or R2013b
R2014b or later,
R2015a or later,
Octave 4.2.2 (32bit / 64bit) 4.2.2 4.2.2 (3.4.3)
Python Py27 (32bit1,2 / 64bit2),
Py35 (32bit2 / 64bit2),
Py36 (32bit2 / 64bit2)

1 Use this when you have Python(x,y).
2 Check your Python console if you need 32bit or 64bit - bitness should be printed at startup.

or see download page for more options/versions ...

Unzip in your home directory and adapt the path:

Matlab/Octave Python
import casadi.*
x = MX.sym('x')
from sys import path
from casadi import *
x = MX.sym("x")

Get started with the example pack.

Getting error "CasADi is not running from its package context." in Python? Check that you have casadi-py27-v3.4.4/casadi/ If you have casadi-py27-v3.4.4/ instead, that's not good; add an extra casadi folder.

What follows are more detailed install instructions.

If you are new to (scientific) Python, first install it on Linux or Windows.

If you have installed a release of CasADi older than 2.3.0, it is highly recommended to remove it first: use the "remove installed programs" functionality on Windows, or sudo dpkg --remove python-casadi in Linux, and follow the instructions below. Versions later than 2.3.0 can happily coexist.

The binaries include the solvers that are distributed with the tool (Sundials, qpOASES, CSparse) as well as IPOPT (shipped with the MUMPS linear solver; HSL is available through IPOPT's dynamic loader).

Some plugins require extra prerequisites to work on Linux. You can deal with them after you get basic CasADi up and running.

On our download page, locate and download the binary archive of your choice:

Python Matlab
Linux/Mac casadi-py*-np*-*.tar.gz casadi-matlab*-*.tar.gz
Windows casadi-py*-np*-*.zip casadi-matlab*-*.zip

Note: the Windows binaries are all for 64-bit systems. The default binary is for a 32-bit python installation on the 64-bit system (like the one provided by python-(x,y)). There is a variant with "-64" appended to the name for a 64-bit Python installation. Note: some binaries have "-Debug" appended to their names. These run slower, but have debugging info included.

Simply extract the archive such that a folder with the same name as the archive is created. We will refer to this folder as casadiinstalldir. It may be e.g. "C:\Downloads\casadi-py27-np1.9.1-v3.2.0" in your case.

Note: some users have reported problems when CasADi is put in the 'toolbox' directory of Matlab itself (errors like: NewPointerObj problem. creating SwigRef as opposed to casadi.DM). Better not do that, just put in your home.

You can immediately test out the installation:

In Python:

import sys
from casadi import *
x = MX.sym("x")
print jacobian(sin(x),x)


import casadi.*
x = MX.sym('x')

Please contact us if this mechanism fails for you, or if you wish to see support for other versions.

To make the installation more permanent:

For Python: add casadiinstalldir to the PYTHONPATH environmental variable

This is system dependent. On Linux/Mac, you would typically add a line like the following to your .bashrc (for Mac .profile) file in the home directory:

export PYTHONPATH=$PYTHONPATH:casadiinstalldir

On Windows, you go to explorer, right click my computer, choose advanced options and select environmental variables.

For MATLAB/Octave: savepath

To help you get started, you can download the example pack.

An unofficial builds can be found for Fedora and CentOS and Archlinux.

Option 2: Build from sources

CasADi is written in self-contained C++, making heavy use of the C++ standard library, thus requiring nothing but a reasonably recent C++ compiler (with support for C++11). To build the code, we use CMake, version 2.8. The Python front-end requires SWIG (version 2.0 or newer). It has been written for Python 2.7, but has also been tested successfully on earlier Python 2.5 and 2.6. We show below how to get these dependencies and then to compile CasADi from sources.

Instructions on how to compile CasADi from sources:

For the Matlab front-end there are generic compile instruction at the Matlab page.

Option 3: CasADi on Conda

A build of CasADi-Python is available for the Conda environment in Linux and Mac (currently no Windows support).

After installing either miniconda or anaconda, installation is as easy as

conda config --add channels conda-forge 
conda install casadi

You should then be able to load up python and import casadi with no problems. If you get errors and don't have a recent conda install, try a conda update conda. Builds are available for Python 2.7, 3.5, and 3.6, and numpy 1.12. The build contains the IPOPT interface, but not any other third-party solvers.

For error reports relating to the conda install, we refer to conda-forge/casadi-feedstock. Thanks to Peter St. John for this contribution.