Installing Theano, Scikit-learn, and Scipy on Windows with Cygwin.

I’ve started writing computer vision applications using Theano but I’ve found it does not work very well with the Windows 7 + Visual Studio 2013 installed in the lab. The Theano docs indicate that Theano “should” be able to work with Cygwin but that it’s not yet been tested.

So I figured I’d try it out. Here is what I did.

1. Grab Cygwin: https://cygwin.com/
2. From the setup, Install fortran, gcc, blas, linspace, and python 2.7 and any other tools you’d like. Don’t forget to install libraries libgfortranlib, gcc-fortran. To reduce the chances of future problems I choose to install the source for these packages also.

3. Get pip working. Use:
chmod 775 /usr/lib
chmod 775 /usr/bin
wget https://bootstrap.pypa.io/ez_setup.py -O – | python
easy_install pip

4. pip install numpy
5. pip install Tempita

Install SciPy with:
mkdir scipy
cd scipy

Use wget https://github.com/scipy/scipy/archive/master.zip to download the very latest source for scipy.

unzip master.zip
cd scipy-master

$ python setup.py install –user

5. pip install scikit-learn

6. pip install six
7. Install theano from latest build.

pip install –upgrade –no-deps git+git://github.com/Theano/Theano.git –user

8. Find location where Theano stores cutils_ext (On my system it is ~/.theano/compiledir_CYGWIN_NT-6.1-2.3.1-0.291-5-3-x86_64-64bit–2.7.10-64/cutils_ext)

Copy cutils_ext.pyd to a new file named cutils_ext.dll (if you don’t than importing theano will fail)

cp cutils_ext.pyd cutils_ext.dll

If you do #6 with just “pip install theano” it will try to uninstall your scipy and proceed to download a buggy one. Don’t let it!

Note: If you came here from google and tried to install scipy 0.16.1 on sunos or cygwin you probably are looking for this:

There is currently a bug in the above scipy branch related to a variable named infinity. It was fixed in november for the master build but not updated to the 0.16.1 archive.

If you use 0.16.1 from that link you’ll get a compile error on cygwin:

“error: Command “g++ -fno-strict-aliasing -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/usr/src/ports/python/python-2.7.10-1.x86_64/build=/usr/src/debug/python-2.7.10-1 -fdebug-prefix-map=/usr/src/ports/python/python-2.7.10-1.x86_64/src/Python-2.7.10=/usr/src/debug/python-2.7.10-1 -DNDEBUG -g -fwrapv -O3 -Wall -I/usr/include/python2.7 -I/usr/lib/python2.7/site-packages/numpy/core/include -Iscipy/spatial/ckdtree/src -I/usr/lib/python2.7/site-packages/numpy/core/include -I/usr/include/python2.7 -c scipy/spatial/ckdtree/src/ckdtree_query.cxx -o build/temp.cygwin-2.3.1-x86_64-2.7/scipy/spatial/ckdtree/src/ckdtree_query.o” failed with exit status 1″
See this commit for more info if you want to investigate that error: https://github.com/scipy/scipy/commit/832baa20f0b5

If you get error:

Traceback (most recent call last):
File ““, line 1, in
File “theano/__init__.py”, line 72, in
from theano.scan_module import scan, map, reduce, foldl, foldr, clone
File “theano/scan_module/__init__.py”, line 41, in
from theano.scan_module import scan_opt
File “theano/scan_module/scan_opt.py”, line 65, in
from theano import tensor
File “theano/tensor/__init__.py”, line 7, in
from theano.tensor.subtensor import *
File “theano/tensor/subtensor.py”, line 26, in
import theano.gof.cutils # needed to import cutils_ext
File “theano/gof/cutils.py”, line 295, in
compile_cutils()
File “theano/gof/cutils.py”, line 260, in compile_cutils
preargs=args)
File “theano/gof/cmodule.py”, line 2014, in compile_str
return dlimport(lib_filename)
File “theano/gof/cmodule.py”, line 289, in dlimport
rval = __import__(module_name, {}, {}, [module_name])
ImportError: No module named cutils_ext

Try step 8 again.