Professional Documents
Culture Documents
InstallationofTheanoonWindowsTheano0.7documentation
Installing Dependencies
Note
Command lines listed below are assumed to be run in a Windows prompt: To open the prompt on Windows <=
7, click Start and type the cmd command to launch a command window. In Windows 8, go to the Start screen
and type command or cmd.
Theano currently works on Windows, however it requires compilers for C/C++ (for Python 2.7 family
this has to be Microsoft Visual Studio 2008 compiler), CUDA (CUDA v5.5 is required as it is the latest
version supporting Visual Studio 2008), and GCC (for non-CUDA C code generated by Theano).
First we need to install Microsoft Visual Studio 2010 Express, which is required to install CUDA. You can
download it from Visual Studio Express. Please install the Visual C version. We have downloaded the allin-one CD, extracted it using 7zip, and ran the installer at VCExpress\setup.exe.
If you want a 64bit Python installation, Visual Studio 2010 Express doesnt provide a 64bit compiler. To
get one download and install the Windows Software Development Kit version 7.1.
Now you have a running (and free even for commercial use) installation of MSVS2010 IDE with 32- and
64-bit compilers.
Once Visual Studio is installed, you can install CUDA. We recommend CUDA 5.5, as it supports MSVC
2008. Download the CUDA installer from the CUDA archive. Be sure to get 32-, or 64-bit version
depending on your system configuration.
Once CUDA is installed you can remove VisualStudio Express 2010.
Finally, grab the Microsoft Visual C++ Compiler for Python 2.7. It provides the now-obsolete compilers
form Visual Studio 2008 that are required for compatibility with Python 2.7. To install the package for all
users please:
1. open an administrators console (got to start, then type cmd, right-click on the command prompt
icon and select runasadministrator)
2. cd to your downloads directory and execute msiexec/iVCForPython27.msiALLUSERS=1
The package will be installed to C:\ProgramFiles(x86)\CommonFiles\Microsoft\VisualC++for
Python\9.0.
Finally download the stdint.h header from here and save it as C:\ProgramFiles(x86)\Common
Files\Microsoft\VisualC++forPython\9.0\VC\include\stdint.h.
GCC
http://deeplearning.net/software/theano/install_windows.html#installwindows
1/8
5/25/2015
InstallationofTheanoonWindowsTheano0.7documentation
Theano C code compiler currently requires a GCC installation. We have used the build TDM GCC which is
provided for both 32- and 64-bit platforms. A few caveats to watch for during installation:
1. Install to a directory without spaces (we have placed it in C:\SciSoft\TDMGCC64)
2. If you dont want to clutter your system PATH un-check addtopath option.
3. Enable OpenMP support by checking the option openmpsupportoption.
download the installation for free. EPD installation includes, in particular, Python (and the development
headers), NumPy, SciPy, nose, sphinx, easy_install, pydot (but not `Graphviz`_, which is necessary for it
to work), g++, and the MKL implementation of blas.
If you want to use the iPython shell, you should first try to import NumPy in it:
C:\Users\user>ipython
[...]
In[1]:importnumpy
If you see an error message telling you that DLLloadfailed, that is probably due to a bug in the script
launching ipython. If C:\SciSoft\Python27 is the directory where you installed EPD, edit
C:\SciSoft\Python27\Scripts\ipython.bat, there should be a line saying:
setpath="C:\SciSoft\Python27";%path%
Alternative: Canopy
Canopy is another software that installs all Theano dependencies. If you are affiliated with a university
(as student or employee), you can download the installation for free.
Install Canopy x64, and update it to the latest version (Help/Softwareupdates...), as older
Canopy versions have trouble installing pip.
Then install pip from Canopy Package Manager.
In the Windows Prompt, type pipinstalltheano.
In Canopy Package Manager, search and install packages mingw 4.5.2 and libpython 1.2
http://deeplearning.net/software/theano/install_windows.html#installwindows
2/8
5/25/2015
InstallationofTheanoonWindowsTheano0.7documentation
(Needed only for Theano 0.6rc3 or earlier) The libpython 1.2 package installs files libpython27.a
and libmsvcr90.a to C:\Users\<USER>\AppData\Local\Enthought\Canopy\User\libs. Copy the two
files to C:\Users\<USER>\AppData\Local\Enthought\Canopy\App\appdata\canopy1.0.0.1160.win
x86_64libs.
(Needed only for Theano 0.6rc3 or earlier) Set the Theano flags blas.ldflags=LC:\Users\
<USER>\AppData\Local\Enthought\Canopy\App\appdata\canopy1.0.0.1160.winx86_64\Scripts
lmk2_corelmk2_intel_threadlmk2_rt.
Alternative: Anaconda
ContinuumIO is providing a free Python distribution for Windows (32-bit and 64-bit), including all
dependencies of Theano. If you are not eligible for a download of EPD or Canopy (via a commercial, or
free academic licence), this is the easiest way to install Theanos dependencies. Simply download and
execute the installer from Anaconda download page, and execute the following in Windows command
line:
$condainstallmingwlibpython
Alternative: Python(x,y)
If you do not have a commercial licence of EPD, and are not eligible to a free academic licence, and
neither Python nor MinGW is installed on your computer, you can install most dependencies of Theano
with Python(x,y). It is a single installation file that contains additional packages like NumPy, SciPy,
IPython, Matplotlib, MinGW, Nose, etc. Note however that there is no 64 bit version currently available.
You can keep the default install options, except that the installation directory should not contain any
blank space (in particular, do not install it into C:\ProgramFiles).
Alternative: manual installation
The following instructions provide steps for manual installation of all Theano dependencies. Note that it
should be possible to run Theano with Cygwin instead of MinGW, but this has not been tested yet.
For 32 bit MinGW: from the MinGW files, download the latest version of the AutomatedMinGW
Installer (mingwgetinst) and install it (you should install all optional components, except the
For 64 bit MinGW (note that manual installation for 64 bit is experimental): download the latest
version of MinGW-w64 from the projects releases page, and extract it for instance to C:\mingw64.
Also download MSYS from this page (although it is a 32-bit version of MSYS, this does not matter
since it is only a convenience tool). Extract MSYS into the same folder, so that, for instance, you
end up with C:\mingw64\msys. Run C:\mingw64\msys\msys.bat and in the MSYS shell, type
sh/postinstall/pi.sh
and answer the few questions so that MSYS is properly linked to your MinGW install.
It is recommended to set your MSYS home to be the same as your Windows home directory. This
will avoid inconsistent behavior between running Theano in a Windows command prompt vs. a
MSYS shell. One way to do this without setting a global Windows HOME environment variable (which
may affect other programs) is to edit your msys.bat file (found e.g. under C:\MinGW\msys\1.0 or
C:\mingw64\msys) and add the following line at the beginning (note that you may need to use e.g.
Wordpad to edit this file, since Notepad gets confused by Unix-style line breaks):
setHOME=%USERPROFILE%
http://deeplearning.net/software/theano/install_windows.html#installwindows
3/8
5/25/2015
InstallationofTheanoonWindowsTheano0.7documentation
If you do not have them already, install the latest versions of Python 2.x and corresponding NumPy
then SciPy packages (simply use the executable installers). Note that there are currently no official
64 bit releases of NumPy and SciPy, but you can find unofficial builds here.
Ensure that the Python installation directory and its Scripts sub-directory are in your system path.
This may be done by modifying the global PATH Windows environment variables, or by creating a
.profile file in your MinGW home, containing a line like export
PATH=$PATH:/c/Python27:/c/Python27/Scripts (note that the latter will work only when you run
If you are installing the 64 bit version, you will need the following hack to be able to compile
Theano files with GCC (skip this step if you are using the 32 bit version). In a temporary work
dlltooldllnamepython27.dlldefpython27.defoutputliblibpython27.a
Finally, copy the libpython27.a file that was generated into your C:\\Python27\\libs folder.
In order to run Theanos test-suite, you will need nose. After unpacking its source code (you may
use 7-zip), you can build and install it from within its code directory by running the following
command (either from a Windows command prompt or an MSYS shell):
pythonsetup.pyinstall
Visual Studio was added to the PATH. Save the following shell script as c:\scisoft\env.bat to configure
the system path:
REMconfigurationofpaths
setVSFORPYTHON="C:\ProgramFiles(x86)\CommonFiles\Microsoft\VisualC++forPython\9.0"
setSCISOFT=%~dp0
REMaddtdmgccstuff
setPATH=%SCISOFT%\TDMGCC64\bin;%SCISOFT%\TDMGCC64\x86_64w64mingw32\bin;%PATH%
REMaddwinpythonstuff
CALL%SCISOFT%\WinPython64bit2.7.9.4\scripts\env.bat
REMconfigurepathformsvccompilers
REMfora32bitinstallationchangethislineto
REMCALL%VSFORPYTHON%\vcvarsall.bat
CALL%VSFORPYTHON%\vcvarsall.batamd64
REMreturnashell
cmd.exe/k
The script assumes that you installed WinPython distribution, update the winpython line otherwise. For a
32 bit installation please change the indicated line to load 32-bit Microsoft Compilers.
You can access the Python shell by double-clicking on c:\scisoft\env.bat. Please do so, and verify that
the following programs are found:
1. where gcc
2. where gendef
3. where cl
http://deeplearning.net/software/theano/install_windows.html#installwindows
4/8
5/25/2015
InstallationofTheanoonWindowsTheano0.7documentation
4. where nvcc
Finally we need to create a link library for GCC. Open up the Python shell and cd to c:\SciSoft. Then
execute:
gendefWinPython64bit2.7.9.4\python2.7.9.amd64\python27.dll
dlltooldllnamepython27.dlldefpython27.defoutputlibWinPython64bit2.7.9.4\python2.7.9.a
Installing Theano
Once the dependencies are installed, you can download and install Theano. We have found that in the
long run, the Git install is the most useful, because you can update it with a single gitpull command.
Therefore we recommend it. However, a manual install without Git is also possible.
Git Install
Theano is hosted on GitHub, you need Git to download it. For Windows, download and install the
MSYSGIT build. Open up the GitShell in the directory in which you want to install Theano. For the
bleeding-edge version execute
gitclonehttps://github.com/Theano/Theano.git
For the latest stable release 0.7 (as of March 2015) run instead:
gitclonehttps://github.com/Theano/Theano.gitbranchrel0.7
Either way, a folder Theano will be created with the library downloaded to it.
Manual Installation
To get the latest bleeding edge version got to Theano on GitHub and download the latest zip. Then
unzip it somewhere.
Alternatively, you can check the latest release release 0.7 (as of March 2015) by going to
https://github.com/Theano/Theano/releases/tag/rel-0.7 and downloading the zip.
Configuring Theano
Once you have installed Theano, open the Python Shell (e.g. c:\scisoft\env.bat if you follow the
installation directories from this tutorial) and cd to it. Then run:
pythonsetup.pydevelop
this step will add the Theano directory to you PYTHON_PATH environment variable.
At this stage you can check whether Theano works and is able to compile C code for CPU execution.
Create a test file containing:
importnumpyasnp
importtime
importtheano
A=np.random.rand(1000,10000).astype(theano.config.floatX)
B=np.random.rand(10000,1000).astype(theano.config.floatX)
np_start=time.time()
AB=A.dot(B)
np_end=time.time()
X,Y=theano.tensor.matrices('XY')
http://deeplearning.net/software/theano/install_windows.html#installwindows
5/8
5/25/2015
InstallationofTheanoonWindowsTheano0.7documentation
mf=theano.function([X,Y],X.dot(Y))
t_start=time.time()
tAB=mf(A,B)
t_end=time.time()
print"NPtime:%f[s],theanotime:%f[s](timesshouldbeclosewhenrunonCPU!)"%(
np_endnp_start,t_endt_start)
print"Resultdifference:%f"%(np.abs(ABtAB).max(),)
Then run it. It should execute without problems and the Theano function should run at a speed similar
to the regular NumPy multiplication. (Both Numpy and Theano should call the same BLAS routine for
matrix multiplication)
create under Windows). It should be placed in the directory pointed to by the %USERPROFILE% variable.
Please note, that WinPython changes it to WinPythonDir\settings (so in our system this corresponds to
c:\scisoft\WinPython64bit2.7.9.4\settings.
Rerun the simple test file and verify that it runs. Depending on you GPU, the theano function should run
on the GPU much faster than the CPU matrix multiplication performed by NumPy. You can also find
additional test code and useful GPU tips on the Using the GPU page.
This will run tests in batches of 100, which should avoid memory errors. Note that this script calls
nosetests, which may require being run from within an MSYS shell if you installed Nose manually as
described above.
Note
In Theano versions <= 0.5, theanonose was not included. If you are working with such a version, you can call
this command instead:
pythontheano/tests/run_tests_in_batch.py
http://deeplearning.net/software/theano/install_windows.html#installwindows
6/8
5/25/2015
InstallationofTheanoonWindowsTheano0.7documentation
If you want a faster and/or multi-threaded BLAS library, you can compile OpenBLAS (ATLAS may work
too, but was not tested, and is usually reported to be slower and more difficult to compile especially
on Windows). OpenBLAS can be downloaded as a zip file from its website (we tested v0.2.6). To compile
it, you will also need MSYS and wget (installation steps are described below).
If you already have a full install of MinGW, you should have MSYS included in it, and thus should be able
to start a MinGW shell. If that is the case, you can skip the following MSYS installation steps. Note that
these steps were written for Python(x,y), but should also work for other bundle Python distributions like
EPD (changing paths accordingly, for instance in EPD 7.3.2 the MinGW folder is EPD7.3.2\EGG
INFO\mingw\usr\i686w64mingw32). To install MSYS on top of the MinGW installation included within
Python(x,y), do as follows:
If mingwget cannot be found automatically, just navigate first into the folder were it was extracted
(it is found in the bin subfolder).
Edit pythonxy\mingw\msys\1.0\msys.bat (e.g. in Wordpad) and add as first line set
HOME=%USERPROFILE%. Then create an easily accessible shortcut (e.g. on your desktop) to this file,
run it and within the MSYS console, run the MSYS post-install script:
/postinstall/pi.sh
It will ask for your MinGW installation directory (e.g. c:/pythonxy/mingw; note the forward slashes).
Once you have a working MinGW/MSYS shell environment, you can go on as follows:
a. Install wget by running the setup program you can download on the wget website.
Note that this setup does not add wget into the system PATH, so you will need to
modify the PATH environment variable accordingly (either in Windows or in a .profile
startup file in your MinGW home). Once this is done, type wgetversion in a MinGW
shell to verify that it is running properly. Note also that if you are behind a proxy, you
should set up your HTTP_PROXY environment variable, or use a custom wgetrc config
quickbuild.win321>log.txt2>err.txt
can also be changed in Python for testing purpose (in which case it will remain only for
the duration of your Python session):
http://deeplearning.net/software/theano/install_windows.html#installwindows
7/8
5/25/2015
InstallationofTheanoonWindowsTheano0.7documentation
theano.config.blas.ldflags="LX:\\YYY\\YYYlopenblas"
f. To test the BLAS performance, you can run the script theano/misc/check_blas.py.
Note that you may control the number of threads used by OpenBLAS with the
OPENBLAS_NUM_THREADS environment variable (default behavior is to use all available
cores). Here are some performance results on an Intel Core2 Duo 1.86 GHz, compared
to using NumPys BLAS or the un-optimized standard BLAS (compiled manually from
its source code). Note that we report here results for GotoBLAS2 which is the ancestor
of OpenBLAS (this benchmark still needs to be updated with OpenBLAS results):
GotoBLAS2 (2 threads): 16s
http://deeplearning.net/software/theano/install_windows.html#installwindows
8/8