Build MXNet

You should now be inside the Raspberry Pi OS file system as root with the # prompt.

Install required software to build MXNet.


            apt update
apt upgrade -y
apt-get -y install git cmake ninja-build gfortran liblapack* libblas* libopencv* libopenblas* python3-dev python3-pip python-dev virtualenv
pip3 install Cython

Instead of root change to user pi to build the application.


            su pi

Change to the home directory for user pi, this is the default user for Raspberry Pi OS.


            cd $HOME

Clone the MXNet application from GitHub.


            git clone --recursive
cd incubator-mxnet

Create a new directory for the build.


            mkdir build
cd build

Run the build commands, cmake to configure the build and ninja to do the compilation.


             cmake \
-GNinja ..

Use the -j option with the number of available CPUs.


            ninja -j8

Wait for the compile to complete. The required time to finish depends on the machine speed and number of CPUs available. More CPUs will shorten the compile time.

When the compile is complete, install the application.


            cd ../python
sudo pip3 install -e . 

Test the result with Python.

Using a text editor copy and paste the code below into a text file named


            import mxnet

Run the example code:


            python3 ./

The version of MXNet should be printed.

The expected output format is below. Your version may be slightly different.





Building MXNet takes about 20 minutes on an AWS c6g.2xlarge EC2 instance.

A native build on a Raspberry Pi 4 can be done using the steps above. Setting the number of jobs too high will result in out of memory failures. With -j4 and the build fails, even on a Raspberry Pi with Gb RAM. With -j1 the build completes, but takes over 6 hours.

Continue to the next section to download the new image and install it on a Raspberry Pi for testing.