Installing Theano & Pylearn2 (and even GPU) On Windows

One comment (might save your time) before starting: If you already have some kind of Python on your system, my best advice would be to completely delete & remove all evidence (like PATH, PYTHONPATH and all other side effects).  It is possible to keep it but you will have to work MUCH harder, trust me on this, been there done that!

So here we start:

Here is a configuration that worked for me on a fresh installation of Windows 8.1 64-bit + Geforce GTX 645:

1. Download&Install Visual Studio 12.0 (we will need its compiler)
2. Download&Install CUDA 64-bit:
3. Download&Install Anaconda 64-bit VERSION 2.1.0:
4. Download&Install Git-scm:

I am assuming that you have chosen default locations during all the installations so far, if you changed anything – you should be smart enough to change it in the following lines as well. (ie. Anaconda is at “C:\Anaconda\”, etc)

I will create a directory “E:\Git\” in which I will store theano and pylearn2.  Again, if you change this,

5. Install Theano (Run the following in an Admin command prompt)

cd E:\Git
git clone git://
cd Theano
python develop

6. Install Pylearn2 (Run the following in an Admin command prompt)

cd E:\Git
git clone git://
cd pylearn2
python develop

7. Create a text file “C:\Users\\.theanorc” and put the following text into it:

floatX = float32
device = gpu

compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin

You are done.

Now, let’s test it:

Python 2.7.8 |Anaconda 2.1.0 (64-bit)| (default, Jul 2 2014, 15:12:11) [MSC v.1
500 64 bit (AMD64)]
Type “copyright”, “credits” or “license” for more information.

IPython 2.2.0 — An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: and
? -> Introduction and overview of IPython’s features.
%quickref -> Quick reference.
help -> Python’s own help system.
object? -> Details about ‘object’, use ‘object??’ for extra details.

In [1]: import theano
Using gpu device 0: GeForce GTX 645

If you see the “Using gpu…” line at the bottom – it is a good sign.

Let’s test a bit more:

E:\Git\Theano>ipython theano\misc\
Using gpu device 0: GeForce GTX 645

Some results that you can compare against. They were 10 executions
of gemm in float64 with matrices of shape 2000×2000 (M=N=K=2000).
All memory layout was in C order.


We executed 10 calls to gemm with a and b matrices of shapes (2000, 2000) and (2000, 2000).

Total execution time: 0.38s on GPU.

Try to run this script a few times. Experience shows that the first time is not as fast as followings calls. The difference is not big, but consistent.

That’s it.  You are good to go!

Good luck.


28 thoughts on “Installing Theano & Pylearn2 (and even GPU) On Windows”

  1. Just followed the (admirably simple) steps, but when I get to the “import theano” step, it fails because it is trying to compile something with g++. Can it use the Visual Studio compiler or should I install MinGW and g++?


      1. I’ve got Visual Studio 2012, so I put this into .theanorc

        compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\BIN\amd64

        That path is where cl.exe is located.

        I ended up installing g++ and managed to get theano to import.

        Do you have g++ on the machine where set up Theano?


  2. Which version of visual studio “exactly” did you have installed?
    (I have VS2013 installed – didn’t work. PyLearn2 gave an error on not detecting any supported versions, and “Cuda is installed, but target GPU is unavailable”).

    I downloaded VS2012 express, but it wants to install to “VS 11.0” , so I’m unsure if it’s the correct version . [Vs community/express; 2013/ 2012… ]


    (Getting Theano and it’s buddies to work is a real nightmare on a windows PC + GPU 😦 . Still, your guide got me closer than the other ones I tried to the thing working.. ).


    1. Sorry for the late reply, if you are still interested in this. I have installed it again and received similar errors to the ones other visitors reported.

      The solution was to install a very specific version of Anaconda – Anaconda 2.1.0

      Liked by 1 person

    1. Yes. I installed Visual Studio 2013 Ultimate on my machine. However, the only thing it uses is the C compiler. PS as for CUDA 6.5, it was impossible to use other compilers if you are also interested in integrating cuDNN, because NVIDIA compiled the library with Visual Studio.


      1. I have not tried these editions. But basically it should only use their C compiler that, as far as I know, they all share.

        Have you tried the exact version of Anaconda mentioned in the post?


  3. First of all, thanks for a wonderful guide. I was about to give up.
    I got it working with Visual Studio 2013 and CUDA 7 following your instructions.

    As you said, Anaconda 2.1.0 works out of the box and Anaconda 2.2.0 doesn’t.

    To make Anaconda 2.2.0 work you have to run the following command after installing it:

    conda install mingw libpython

    Liked by 2 people

  4. I am a bit confused about how to do step 5. Where do you put the folder E:\Git? When I run git clone git:// Windows does not recognize git as a command.


  5. Thank you so much! This was INCREDIBLY helpful!

    Today I just received my ASUS K501 Windows 8.1 laptop with an NVIDIA GeForce 950M GPU. As a result I had a “clean slate” to work with.

    I installed, in order:

    1. Visual Studio 2013 Community Edition
    2. CUDA 7 toolkit: NOTE, at the start of the installation I got a warning saying that the graphics driver could not find compatible graphics hardware. No worries: just continue and do a CUSTOM (Advanced) installation….and deselect the Graphics Driver checkbox (which also automatically deselects the GPU Deployment Kit). All you really need here is the CUDA Toolkit.
    3. Git for Windows
    4. Anaconda Python 3.4 for Window (the latest version that’s out there now)
    5. Once this was all set up: at the Windows Command Prompt I installed
    mingw by typing “conda install mingw libpython”
    6. Then per step 5 above I created a separate folder for downloading Theano from GitHub and did the python develop from the Theano folder that was created.
    7. Regarding the .theanorc.txt file: I just had to change the flags parameter to “=-LC:\Anaconda3\libs” since I am using Python3, and put it in my C:\Users\Brian folder.

    That…was….IT! First time importing Theano, it immediately noted that it was running on my GeForce 950M GPU…and running with IPython from the Command Prompt tested out perfectly.

    Again, thanks so much!

    Liked by 1 person

  6. BTW, one more note: I returned to this to install PyLearn2 after having successfully installed Theano.

    Installing PyLearn2 following Step 6 of the instructions above threw an error:

    “undefined reference to ‘rand_r’

    To fix this:

    navigate to the \pylearn2\pylearn2\utils folder:

    Open the _windows_flip.pyx file with Notepad:

    Add a small ‘u’ before “Windows” on the line starting with:

    IF UNAME_SYSNAME == “Windows”:

    After the change made and file saved, go back to the Command Prompt and rerun the command “python develop” and PyLearn2 was successfully installed!


  7. Thank you very much for this tutorial, it was very useful. I’ve been struggling with this for quite a long time, and finally this helped. I’ve just had to put the .theanorc file into “C:\\Users\\MyUsername\\” to make it work with GPU. Thanks!


  8. I am getting the following error when I run the command “python develop” in top directory of pylearn2.

    Looking for python27.dll
    Building msvcr library: “C:\Anaconda\libs\libmsvcr90d.a” (from C:\WINDOWS\winsxs
    error: [Error 2] The system cannot find the file specified

    I am surprised nobody else got this error. BTW I have looked for the folder and it seems I already have the file, but still cannot figure out why I am getting this error. Any help would be much appreciated.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s