Installing Apache MXNet Python library Windows 10

Hello, hello.

I wanted to share a quick how-to install MXNet on Windows 10 64-bit.

The solution here is a bit opinionated as I am using Anaconda to manage Python environments.

I will start from the beginning – Anaconda installation.

We will need Anaconda 4.3. You should use 64-bit Anaconda/Python 2.7 combination, as the environment we will create will be based on Python 2.7 64-bit in order to support MXNet. You can get anaconda here:

Follow the installation instructions and once it is done, lets go to the windows command line and type this:

conda create -n mxnet python=2.7 anaconda

having ‘anaconda’ argument in there will ensure we have common data analytics libraries, that are not necessary for MXNet, but nice to have. Also, we want to use Python 2.7 in this case, as MXNet has compatibility issues with Python 3.

Once the environment creation is complete, activate it by executing:

activate mxnet

It is all for the terminal so far.

Lets get pre-combiled MXNet dlls!

You will need to download several packages from

First, get the prebuild VC14 ( Visual Studio runtime 2015) package, it doesn’t contain any specific binaries, but it provides 3rd party libraries and helps to set all the environment variables that are necessary to run MXNet. In my case I got prebuildbase_win10_x64_vc14 

Once you download VC14 base archive, extract its contents somewhere. A good folder candidate would be ‘mxnet’ in the root of C: or any other drive. Let’s imagine that you have created ‘D:\mxnet’ folder.

Open terminal in that folder an run


It should finish quickly. You can verify that it was successful by going into the System -> Advanced System Settings and making sure it has MXNET_HOME:”D:\mxnet” environment variable setup.

Now, lets download GPU or CPU version of pre-compiled MXNet from the same page where you got the base package. At the moment of writing it is 20170702_mxnet_x64_vc14_gpu.7z

We won’t need the source code of mxnet, as we are not going to compile it from scratch, so you can IGNORE Source code (zip)

The archive will have contents that you need to extract to “D:\mxnet”, it might overwrite some of the folders, which is ok.

Optional STEP:

Now, if you used GPU version of MXNet, the last part would be is to get the cuDNN nVidia library for windows, you will have to register to get it, but essentially it is free.

cuDNN is available here:

Once you download the archive, extract its contents to “D:\mxnet\3rdparty\cudnn”.

END OF Optional STEP.

It is time now to try to install python binding, so you can import mxnet inside a python project.

Go to the terminal where you had your MXNet Anaconda environment activated and jump to the location: “D:\mxnet\python”. Once you are in the correct location, run

python install

If it ran without any errors, then we are ready to do our final test. Go back to the terminal where you acivated mxnet environment and first, start Python interpreter, and then run

import mxnet

You should be able to import the library.




  1. Hi, thanks for the instructions. However when I try to import mxnet I get the error “ImportError: cannot import name Union”. Any idea how to solve this?

    • Hey TheJude,
      I have a few questions for you. Are you using GPU or CPU version of the MXNet?

      First thing, make sure you get all windows packages from
      You will need vc14 base package, 20170330_mxnet_x64_vc14_gpu.7z or *_cpu.7z and Source code (zip)

      I personally did not see import problems with Union.

      Also, take a look at the environment variables on the Windows system, and make sure MXNET_HOME is set to the location where you extracted your packages.
      Lastly, if you are using GPU version, you will need to download cuDNN from Nvidia and place its contents into 3rdparty folder inside mxnet location.

  2. Thanks alot for the instructions!
    I have 2 questions please.
    1- I have an error in the last step import mxnet called
    WindowsError: [Error 126] The specified module could not be found
    2- Should I download the source code file when I download base VC14 ? If yes what will I do with it? where I am going to extract it?
    What shall I do?
    I am using cpu

    • hey!
      Make sure you do this:
      1. In the terminal, execute command `activate mxnet`
      2. Download source code(not vc14) and extract it somewhere. I have it located in the D:\mxnet
      3. Inside the terminal window where you did `activate mxnet`, go to D:\mxnet\python ( D: or other drive, depends where you extracted it) and run
      4. `python install`

      • Thanks for your fast response.
        I had two issue in fact.
        1- when I installed anaconda and tried to run:
        conda create -n mxnet python=2.7 anaconda
        I got an error saying:
        ‘conda’ is not recognized as an internal or external command.
        I solved it by executing the command in anaconda prompt.
        2- error when run :
        import mxnet
        WindowsError: [Error 126] The specified module could not be found
        solved it by opening anaconda prompt mxnet (It have been created after running activate mxnet), then run python, then import mxnet. No errors popped up, but I have no code to try is everything else if fine or not!
        I installed 20170605_mxnet_x64_vc14_cpu.7z and unzipped it, I did not download or used Source code (zip) file (these are from the link given:
        Please, can you explain the differences between the two files? and why it went fine with me?

        • The source code files can be used to do the compilation of the `libmxnet.dll`
          You still need to download the base package and run the `setupenv.cmd` to setup all the environment variables.
          An example how it looks on my machine is here –

          You can run the `python install` inside the terminal where you have run `activate mxnet` – this command should have activated Conda environment called `mxnet` with its own, isolated python environment.

  3. 1- Execuse me to ask, but where exactly in the previous steps we downloaded and installed mxnet?
    2- How can we verify that mxnet is working proberly? (even if the import mxnet work fine)
    3- in the last step import mxnet, do you mean open python on the terminal and then import mxnet inside it, or do you mean import python outside python?
    4- when I installed Anaconda, I found anaconda navigator (maxnet), jupyter (mxnet), …. , what does these applications means? are they supporting mxnet?

    Thanks in advance

    • I will start from the bottom.

      Anaconda allows you to create virtual python environments. In a virtual environment, you can install and manage packages separately from the root python installation. It gives you an option to have a space with specific versions of python and its modules.
      When we created `mxnet ` environment, we also pulled some of the common data science libraries and made it an isolate space where you can perform machine learning and data science work.
      When we activate an environment in Anaconda, it just means we want to work in that isolated space, meaning if we install or remove packages, such as `mxnet`, it will only take effect inside that particular env.

      The last step can be described as follows, I think I made it a bit vague in the tutorial. First, you need to open terminal and run
      `activate mxnet` – it will activate python virtual environment
      Second, run python interpreter
      and last step would be trying to import mxnet
      `import mxnet`

      You can verify that mxnet was installed and working by doing some simple mxnet operations.
      After you run `import mxnet`, you can execute following in the same terminal window:
      Which should print a shape of the created tensor.

      1: mxnet as a library with python package comes in the precompiled cpu archive. There is also VC14 package available for download, that you need in order to setup environment variables and have some of the necessary 3rd party tools. Essentially, you only need the precompiled archive after you setup windows environment variables.

  4. Hi,
    thank you very much for your installation guide! I followed it, however when I finally “import mxnet” I get the following error:

    AttributeError: function ‘MXListAllOpNames’ not found

    Full detail below. Do you have any recommendation?
    File “”, line 1, in
    import mxnet

    File “C:\Users\Hank\Anaconda3\envs\mxnet\lib\site-packages\mxnet-0.10.1-py2.7.egg\mxnet\”, line 9, in
    from . import contrib

    File “C:\Users\Hank\Anaconda3\envs\mxnet\lib\site-packages\mxnet-0.10.1-py2.7.egg\mxnet\contrib\”, line 10, in
    from . import autograd

    File “C:\Users\Hank\Anaconda3\envs\mxnet\lib\site-packages\mxnet-0.10.1-py2.7.egg\mxnet\contrib\”, line 10, in
    from ..ndarray import NDArray, zeros_like

    File “C:\Users\Hank\Anaconda3\envs\mxnet\lib\site-packages\mxnet-0.10.1-py2.7.egg\mxnet\”, line 2514, in
    _init_ndarray_module(NDArray, “mxnet”)

    File “C:\Users\Hank\Anaconda3\envs\mxnet\lib\site-packages\mxnet-0.10.1-py2.7.egg\mxnet\”, line 2492, in _init_ndarray_module

    File “C:\Users\Hank\Anaconda3\envs\mxnet\lib\ctypes\”, line 375, in __getattr__
    func = self.__getitem__(name)

    File “C:\Users\Hank\Anaconda3\envs\mxnet\lib\ctypes\”, line 380, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))

    AttributeError: function ‘MXListAllOpNames’ not found

  5. Would be great! 🙂 I am running Windows 10, Python 2.7.13 |Anaconda 4.4.0 (64-bit). The mxnet Folder is directly in my c drive, i.e. C:\mxnet. The mxnet environment is in my user Directory C:\Users\Hank\Anaconda3\envs\mxnet.
    Do you need more Information?

  6. I have a question, a framework should be something like ApacheMXNet, so these steps are for the MXNet library, right?

      • Thanks Stan , actually I noticed that but got confused with the term Apache MXNet.
        1- What I know is that mxnet is a library like tensorflow, keras, theano; I mean we use it as syntax (not a server), right?

        2- so please what is it Apache MXNet?
        3- When do we need to use it?
        4- If I am building a ANN with mxnet and want it to run on a cloud, should I use Apache MXNet?

        Thanks in advance

        • Hi Esraa,
          I’ll answer one by one:
          1. MXNet is a framework that recently joined Apache –
          1a. Thus there is a confusion in name. Also, the library part comes into the picture when it is necessary to choose what binding you want to use, MXNet for Python, Scala, JavaScript and so on.

          2. Apache MXNet is the new name for MXNet, as the developers moved the project under Apache Foundation.
          3. There is no difference between MXNet and Apache MXNet
          4. If you are using Amazon EC2 instances to do deep learning, you will be using MXNet, it just Amazon started to call it Apache MXNet recently.

  7. Hiya,
    Thanks for a great post! I’ve been following it throughout, but I an running into the same error as another chap here in the comments, but his comment doesn’t state whether he resolved it.

    In my case, this *may* be because I am trying to run this in python 3. If you think this is the reason, do let me know.

    I end up with the error “OSError: [WinError 126] The specified module could not be found”.

    My path is correct, with environment variables like “MXNET_HOME;” pointing in the correct location with the correct conda env enabled.

    Do you have any other advice?

    • When I’ve used Python 3 for installation, I had similar problem. What I’ve done is I found python module that comes with MXNet source and manually copied into python3 installation folder under site-packages, as it was empty.
      If you are using anaconda, your site packages should be located under anaconda/python.

  8. Hi PQXK8,
    Thanks alot for your fast responce always, actually now I have a question about MXNet but not the installation of it.

    I installed it as you mentioned and used it for CNN, but now after I trained it, I want to test my model on a certain image (prediciton should be 0 or 1 with the corresponding probability) but I don’t know how to do it, so I used the following code which I found on internet, but it gives many lables not only 0 and 1!
    Hint: argmax gives 0 and 1, argmin gives many lables 0,23,47,16 …
    If you know any way or a documentation that may help, please.
    Can you check it please:

    img = img[np.newaxis, :]
    img = mx.nd.array(img)
    Batch = namedtuple(‘Batch’, [‘data’])
    sym, arg_params, aux_params = mx.model.load_checkpoint(‘mymodel’, 5)
    mod = mx.mod.Module(symbol=sym)
    mod.bind(for_training=False, data_shapes=[(‘data’, (1,1,20,20))],label_shapes=mod._label_shapes)
    mod.set_params(arg_params, aux_params)
    prob = mod.get_outputs()[0].asnumpy()
    prob = np.squeeze(prob)
    sortedprobindex = np.argsort(prob)[::-1]
    for i in sortedprobindex[0:1]:
    print(‘probability=%f, class=%s’ %(prob[i], prob.argmax()))

    • Hey Esraa, what is the shape of label_shapes array? And what are the few last layers of the network symbol that you are using to do the prediction? Trying to understand the data flow.

      • Training label shape is a column vector = number of images x 1,
        zeros and ones.
        I arranged it in this way as I read the all false images first then the positive images
        both the lables and the images fed to the iterator

        the model is:
        convolution layer + ReLU + max polling
        convolution layer + ReLU + max polling
        Fully connected
        one hidden layer

        it’s just confusing to get the more than 40 class prediction value for the same image, where the trained model is trained with only 2 class 0 and 1

          • Hi Esraa,

            It looks like when you try to call

            print(‘probability=%f, class=%s’ %(prob[i], prob.argmax()))
            prob[i] will return you a probability for a specific example by index i.

            The seems to be with the prob.argmax() call, as it is not really related to the prob[i] or label[i] mapping.
            prob.argmax() should be replaced with a reference to the label at a location [i].

            Another issue could is when you setup your network for binary classification, you should have at the end a two way fully connected layer and a softmax output ( gives out probability)

            So I would check
            1) Mapping to appropriate label, in your case it should be either 0 or 1
            2) Network architecture and the network output on the final shape

  9. Actually you are right I noticed it is not senseing the softmax as it should be, the number of the probabilites from each prediciton is = no. nodes in the fully connected layer!!!
    I am using the softmax activation + loss function compined in the softmax symbol!

    Can you help, please
    I am using this model:
    data = mx.sym.var(‘data’)
    # first conv layer
    conv1 = mx.sym.Convolution(data=data, kernel=(5,5), num_filter=20)
    tanh1 = mx.sym.Activation(data=conv1, act_type=”tanh”)
    pool1 = mx.sym.Pooling(data=tanh1, pool_type=”max”, kernel=(2,2), stride=(2,2))
    # second conv layer
    conv2 = mx.sym.Convolution(data=pool1, kernel=(5,5), num_filter=50)
    tanh2 = mx.sym.Activation(data=conv2, act_type=”tanh”)
    pool2 = mx.sym.Pooling(data=tanh2, pool_type=”max”, kernel=(2,2), stride=(2,2))
    # first fullc layer
    flatten = mx.sym.flatten(data=pool2)
    fc1 = mx.symbol.FullyConnected(data=flatten, num_hidden=500)
    tanh3 = mx.sym.Activation(data=fc1, act_type=”tanh”)
    # second fullc
    fc2 = mx.sym.FullyConnected(data=tanh3, num_hidden=10)
    # softmax loss
    lenet = mx.sym.SoftmaxOutput(data=fc2, name=’softmax’)
    # create a trainable module on GPU 0
    lenet_model = mx.mod.Module(symbol=lenet, context=mx.cpu())
    # train with the same, eval_data=val_iter, optimizer=’sgd’,
    epoch_end_callback = mx.callback.do_checkpoint(“mymodel”, 10),
    #——————–And this for predicting one single new image:
    #load the saved model
    sym, arg_params, aux_params = mx.model.load_checkpoint(‘mymodel’, 1)
    #create a new Module and assign it the input Symbol
    mod = mx.mod.Module(symbol=sym)
    mod.bind(for_training=False, data_shapes=[(‘data’, (1,1,20,20))],label_shapes=mod._label_shapes)
    mod.set_params(arg_params, aux_params, allow_missing=False)
    #get probability for each patch of the image
    for patch in range(patches.shape[0]):
    resize_sliding_patch = patches[patch]
    #edit the axiese of the patch to match the one fed to the nn
    img = resize_sliding_patch[np.newaxis, :]
    img = img[np.newaxis, :]
    img = mx.nd.array(img)
    Batch = namedtuple(‘Batch’, [‘data’])
    prob = mod.get_outputs()[0].asnumpy()
    prob = np.squeeze(prob)
    sortedprobindex = np.argsort(prob)[::-1]
    for i in sortedprobindex[0:1]:
    print(‘probability=%f, class=%s’ %(prob[i], prob.argmax()))

    • Another question please, the labels which fed to the train_iterator I used is an excel sheet of one column vector [0000000 ….. 1111111……], I arranged it in this way as the images being read from the file the -ve will be read first (according to it’s name) and the the +ve images.
      is my concept true or how should I creat the labels?

      train_iterator=, Y_train, batch_size=batch_size,shuffle=True,last_batch_handle=’pad’)#,last_batch_handle=’discard’)

      • Hi Esraa, the training iterator looks fine as long as X_train and Y_train arrays has corresponding positions and equal size.

    • Hi Esraa,
      It looks like the last fully connected layer in the network you use has 10 hidden units. Usually, the fully connected layer needs to have the amount of units equal to the amount of categories – in your case of binary classification you should set it to two units. The softmax as the activation function looks good and it will give you probabilities.
      Hopefully it helps!

      • Thanks alot you were totally right, although I dont know why we should do that, I used different DL library and it was not like this.

        I have a dummy question actually, in this code
        lenet_model = mx.mod.Module(symbol=lenet, context=mx.cpu()),

        Where is the backpropagation happend?

        Thanks alot for your support

        • Hi Esraa, fit function in Python calls _train_multi_device which is in turn calls forward and backward, that does the back-propagation cycle.

    • Hi Valerio, I haven’t tried myself to interface mxnet with scala binding. I’ll post my findings here once I try it out.

Leave a Reply

Your email address will not be published.