This document discusses how to build mlpack from source. However, mlpack is in the repositories of many Linux distributions and so it may be easier to use the package manager for your system. For example, on Ubuntu, you can install mlpack with the following command:
If mlpack is not available in your system's package manager, then you can follow this document for how to compile and install mlpack from source.
mlpack uses CMake as a build system and allows several flexible build configuration options. One can consult any of numerous CMake tutorials for further documentation, but this tutorial should be enough to get mlpack built and installed on most Linux and UNIX-like systems (including OS X). If you want to build mlpack on Windows, see Building mlpack From Source on Windows (alternatively, you can read Keon's excellent tutorial which is based on older versions).
You can download the latest mlpack release from here: mlpack-3.1.1
Assuming all dependencies are installed in the system, you can run the commands below directly to build and install mlpack.
.. command fails, you are probably missing a dependency, so check the output and install any necessary libraries. (See Dependencies of mlpack.)
On many Linux systems, mlpack will install by default to
/usr/local/lib and you may need to set the
LD_LIBRARY_PATH environment variable:
The instructions above are the simplest way to get, build, and install mlpack. The sections below discuss each of those steps in further detail and show how to configure mlpack.
First we should unpack the mlpack source and create a build directory.
The directory can have any name, not just 'build', but 'build' is sufficient.
mlpack depends on the following libraries, which need to be installed on the system and have headers present:
For Python bindings, the following packages are required:
In Ubuntu and Debian, you can get all of these dependencies through apt:
On Fedora, Red Hat, or CentOS, these same dependencies can be obtained via dnf:
(It's also possible to use python3 packages from the package manager—mlpack will work with either.)
Running CMake is the equivalent to running
./configure with autotools. If you run CMake with no options, it will configure the project to build without debugging or profiling information (for speed).
You can manually specify options to compile with debugging information and profiling information (useful if you are developing mlpack):
The full list of options mlpack allows:
mlpack_testprogram (default ON)
mlpack_logistic_regression, etc.) (default ON)
mlpack_testwith verbose output (default OFF)
Each option can be specified to CMake with the '-D' flag. Other tools can also be used to configure CMake, but those are not documented here.
In addition, the following directories may be specified, to find include files and libraries. These also use the '-D' flag.
Once CMake is configured, building the library is as simple as typing 'make'. This will build all library components as well as 'mlpack_test'.
It's often useful to specify
-jN to the
make command, which will build on
N processor cores. That can accelerate the build significantly.
You can specify individual components which you want to build, if you do not want to build everything in the library:
One particular component of interest is mlpack_test, which runs the mlpack test suite. You can build this component with
and then run all of the tests, or an individual test suite:
If the build fails and you cannot figure out why, register an account on Github and submit an issue and the mlpack developers will quickly help you figure it out:
Alternately, mlpack help can be found in IRC at #mlpack on irc.freenode.net.
If you wish to install mlpack to the system, make sure you have root privileges (or write permissions to those two directories), and simply type
You can now run the executables by name; you can link against mlpack with
-lmlpack, and the mlpack headers are found in
/usr/local/include (depending on the system and CMake configuration). If Python bindings were installed, they should be available when you start Python.
If you would prefer to use mlpack after building but without installing it to the system, this is possible. All of the command-line programs in the
build/bin/ directory will run directly with no modification.
For running the Python bindings from the build directory, the situation is a little bit different. You will need to set the following environment variables:
(Be sure to substitute the correct path to your build directory for
Once those environment variables are set, you should be able to start a Python interpreter and
import mlpack, then use the Python bindings.