Installing MXNet from source on OS X (Mac)

The following installation instructions are for building MXNet from source. For instructions to build MXNet from source on other platforms, see the general Build From Source guide.

Instead of building from source, you can install a binary version of MXNet. For that, please follow the information at Get Started.

Building MXNet from source is a two-step process:

  1. Build the shared library from the MXNet C++ source code.
  2. (optional) Install the supported language-specific packages for MXNet.

If you plan to build with GPU, you need to set up the environment for CUDA and cuDNN. Please follow the NVIDIA CUDA Installation Guide for Mac OS X and cuDNN Installation Guide. Note that CUDA stopped supporting macOS in 2019 and future versions of CUDA may not support macOS.

Contents


Build the MXNet shared library from source

On OS X, you need the following dependencies:

Step 1: Install prerequisite packages.

# Install OS X Developer Tools
xcode-select --install

# Install Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

# Install dependencies
brew install cmake ninja ccache opencv

opencv is an optional dependency. You can delete it from above brew install line and build MXNet without OpenCV support by setting USE_OPENCV to OFF in the configuration file described below.

Step 2: Download MXNet sources and configure

Clone the repository:

git clone --recursive https://github.com/apache/mxnet.git mxnet
cd mxnet
cp config/darwin.cmake config.cmake

Please edit the config.cmake file based on your needs. The file contains a series of set(name value CACHE TYPE "Description") entries. For example, to build without Cuda, change set(USE_CUDA ON CACHE TYPE "Build with CUDA support") to set(USE_CUDA OFF CACHE TYPE "Build with CUDA support").

For a GPU-enabled build make sure you have installed the CUDA dependencies first). When building a GPU-enabled build on a machine without GPU, MXNet build can't autodetect your GPU architecture and will target all available GPU architectures. Please set the MXNET_CUDA_ARCH variable in config.cmake to your desired cuda architecture to speed up the build.

To (optionally) build with MKL math library, please install MKL first based on the guide in Math Library Selection.

Step 3: Build MXNet core shared library.

rm -rf build
mkdir -p build && cd build
cmake ..
cmake --build .

Specify cmake --build . --parallel N to set the number of parallel compilation jobs. Default is derived from CPUs available.

After a successful build, you will find the libmxnet.dylib in the build folder in your MXNet project root. libmxnet.dylib is required to install language bindings described in the next section.


Installing Language Packages for MXNet

After you have installed the MXNet core library. You may install MXNet interface packages for the programming language of your choice: - Python - C++ - Clojure - Julia - Perl - R - Scala - Java


Install MXNet for Python

To install the MXNet Python binding navigate to the root of the MXNet folder then run the following:

cd python
pip install --user -e .

Note that the -e flag is optional. It is equivalent to --editable and means that if you edit the source files, these changes will be reflected in the package installed.

Install the MXNet Package for C++

Refer to the C++ Package setup guide.


Install the MXNet Package for Clojure

Refer to the Clojure setup guide.


Install the MXNet Package for R

Run the following commands to install the MXNet dependencies and build the MXNet R package.

    Rscript -e "install.packages('devtools', repo = 'https://cran.rstudio.com')"
    cd R-package
    Rscript -e "library(devtools); library(methods); options(repos=c(CRAN='https://cran.rstudio.com')); install_deps(dependencies = TRUE)"
    cd ..
    make -f R-package/Makefile rpkg

Install the MXNet Package for Julia

The MXNet package for Julia is hosted in a separate repository, MXNet.jl, which is available on GitHub. To use Julia binding it with an existing libmxnet installation, set the MXNET_HOME environment variable by running the following command:

    export MXNET_HOME=/<path to>/libmxnet

The path to the existing libmxnet installation should be the root directory of libmxnet. In other words, you should be able to find the libmxnet.so file at $MXNET_HOME/lib. For example, if the root directory of libmxnet is ~, you would run the following command:

    export MXNET_HOME=/~/libmxnet

You might want to add this command to your ~/.bashrc file. If you do, you can install the Julia package in the Julia console using the following command:

    Pkg.add("MXNet")

For more details about installing and using MXNet with Julia, see the MXNet Julia documentation.

Install the MXNet Package for Scala

To use the MXNet-Scala package, you can acquire the Maven package as a dependency.

Further information is in the MXNet-Scala Setup Instructions.

If you use IntelliJ or a similar IDE, you may want to follow the MXNet-Scala on IntelliJ tutorial instead.

Install the MXNet Package for Perl

Before you build MXNet for Perl from source code, you must complete building the shared library. After you build the shared library, run the following command from the MXNet source root directory to build the MXNet Perl package:

    brew install swig
    sudo sh -c 'curl -L https://cpanmin.us | perl - App::cpanminus'
    sudo cpanm -q -n PDL Mouse Function::Parameters Hash::Ordered PDL::CCS

    MXNET_HOME=${PWD}
    export PERL5LIB=${HOME}/perl5/lib/perl5

    cd ${MXNET_HOME}/perl-package/AI-MXNetCAPI/
    perl Makefile.PL INSTALL_BASE=${HOME}/perl5
    make
    install_name_tool -change lib/libmxnet.so \
        ${MXNET_HOME}/lib/libmxnet.so \
        blib/arch/auto/AI/MXNetCAPI/MXNetCAPI.bundle
    make install

    cd ${MXNET_HOME}/perl-package/AI-NNVMCAPI/
    perl Makefile.PL INSTALL_BASE=${HOME}/perl5
    make
    install_name_tool -change lib/libmxnet.so \
            ${MXNET_HOME}/lib/libmxnet.so \
            blib/arch/auto/AI/NNVMCAPI/NNVMCAPI.bundle
    make install

    cd ${MXNET_HOME}/perl-package/AI-MXNet/
    perl Makefile.PL INSTALL_BASE=${HOME}/perl5
    make install

Contributions

You are more than welcome to contribute easy installation scripts for other operating systems and programming languages. See the community contributions page for further information.

Next Steps