Install & Compatibility
Where this runs
tested against v3.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
build_error
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 6.4s · import 0.280s · 348MB
350MB installed
● package 350MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
casadi
✓ import casadi as ca
Function
✓ solver = ca.nlpsol(...)
✗ solver = ca.SXFunction(...) or ca.MXFunction(...)
In CasADi v3.x, SXFunction/MXFunction were replaced by a unified Function interface, typically accessed via higher-level APIs like nlpsol.
This quickstart demonstrates how to define a simple nonlinear programming problem (NLP) using CasADi's symbolic `MX` variables, formulate it, and solve it using the IPOPT optimizer. It includes defining an objective function and a constraint.
import casadi as ca
import numpy as np
# Declare symbolic variables
x = ca.MX.sym("x")
y = ca.MX.sym("y")
# Define objective function (e.g., Rosenbrock function)
f = (x - 1)**2 + 10*(y - x**2)**2
# Define constraints (e.g., x + y >= 0)
g = x + y
# Formulate NLP problem
nlp = {'x': ca.vertcat(x,y), 'f': f, 'g': g}
# Choose a solver (IPOPT is common, ensure it's available)
solver_opts = {'ipopt': {'print_level': 0}, 'print_time': 0}
solver = ca.nlpsol('solver', 'ipopt', nlp, solver_opts)
# Solve the NLP
# Set lower/upper bounds for variables (lbx, ubx) and constraints (lbg, ubg)
sol = solver(
lbx=[-ca.inf, -ca.inf], ubx=[ca.inf, ca.inf],
lbg=[0], ubg=[ca.inf] # g >= 0
)
print(f"Optimal solution x: {sol['x'].full().flatten()}")
print(f"Optimal objective f: {sol['f'].full().item()}")
casadi --version
Debug
Known issues
breakingMajor API changes occurred between CasADi v2.x and v3.x. Code written for v2.x (e.g., using `SXFunction`, `MXFunction`, or older solver interfaces) will not directly work with v3.x.fixRefer to the v3.x documentation for updated API usage, especially for creating symbolic functions and setting up solvers (e.g., `ca.Function`, `ca.nlpsol`). Migrate old `SXFunction`/`MXFunction` calls to the `ca.Function` API.
affects: All v3.x versions (compared to v2.x)
gotchaCasADi uses different symbolic types (`MX`, `SX`) and numerical types (`DM`, `DMatrix`). Mixing them or using the wrong type can lead to performance issues or errors. `MX` is generally recommended for complex NLPs and AD due to its flexibility, while `SX` is for highly sparse, structured problems.fixBe mindful of the type of symbolic variables you create (e.g., `ca.MX.sym('x')` vs `ca.SX.sym('x')`). For general-purpose nonlinear programming, `MX` is usually the safe choice. Explicitly convert NumPy arrays to CasADi's numerical types (`ca.DM(numpy_array)`) when interacting with CasADi functions. affects: All versions
gotchaCasADi functions are often JIT-compiled to C code. Errors in symbolic expressions might only surface during the compilation step when a function is constructed (e.g., `ca.Function(...)` or `ca.nlpsol(...)`), not necessarily when the symbolic expression is initially defined.fixThoroughly test your symbolic expressions and functions with simple inputs before integrating into larger solvers. Pay close attention to error messages during function compilation, as they often point to issues in the symbolic formulation.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'casadi'
This error occurs when the CasADi library is not installed in the Python environment.
fixInstall CasADi using pip: `pip install casadi`.
ModuleNotFoundError: No module named 'casadi._casadi'
This error occurs when packaging a Python application with PyInstaller without including the 'casadi._casadi' module.
fixAdd 'casadi._casadi' to the hidden imports in the PyInstaller spec file: `hiddenimports=['casadi', 'casadi._casadi']`.
CasADi - WARNING(".../casadi/core/plugin_interface.hpp:322: Assertion \"handle!=nullptr\" failed: PluginInterface::load_plugin: Cannot load shared library 'libcasadi_nlpsol_ipopt.so':
This error occurs when CasADi cannot load the 'libcasadi_nlpsol_ipopt.so' shared library, often due to compatibility issues with the Python version.
fixEnsure that the installed CasADi version is compatible with your Python version. For example, CasADi may not support Python 3.10; consider using Python 3.9 instead.
Unrecognized function or variable 'casadiMEX'
This error occurs when the CasADi MEX file is not properly set up in MATLAB.
fixEnsure that the CasADi MEX file is correctly installed and that the MATLAB path includes the directory containing 'casadiMEX'.
ValueError: p_global feature is only compatible with casadi 3.7.2
This error occurs when using the 'p_global' feature with an incompatible version of CasADi.
fixUpgrade CasADi to version 3.7.2 to use the 'p_global' feature.
Upgrade
Version history
3.8.0latest on PyPI · released Aug 25, 2026
Audit
Dependencies
No dependency data recorded yet.