27

I wonder how to install Theano on Anaconda Python 2.7 x64 on Windows 7 x64. The Theano website provides some instructions but is not clear as to what is specific to Anaconda.

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501

4 Answers4

42

I'm not 100% certain but this may be a minimal set of instructions, but only if you don't want to use a GPU. Getting Theano to use a GPU on Windows is quite a bit more difficult.

  1. Install TDM GCC x64.
  2. Install Anaconda x64.
  3. run conda update conda.
  4. run conda update --all.
  5. run conda install mingw libpython.
  6. Install Theano (how you do this depends on whether you want to interact with the Theano source code or not, and whether you want the "bleeding edge" version, or are happy with the last, but out-of-date major release).
    1. Older version: e.g. pip install Theano.
    2. Bleeding edge version: e.g. pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git (see linked documentation for more options)

If you want multithreading support via OpenMP then things get more complicated.

If you want GPU support things get much more complicated.

The Windows installation instructions in the Theano documentation are fragmented at best, and terribly out of date at worst. If you need more than the basics working on Windows, you'll need to pick your way through to find an approach that works for you.

Daniel Renshaw
  • 33,729
  • 8
  • 75
  • 94
  • 4
    Your step 5. actually installs the gcc/g++ tool-chain with header files and link libraries etc. In my case the compiler was installed under C:\Anaconda\MinGW\bin. By adding this directory to my PATH environment variable, Theano worked fine even without your Step 1. – esskov Jan 26 '16 at 14:42
  • 7
    Correction: After step 5, it is C:\Anaconda\Scripts (or equivalent) that should be added to the PATH, as it contains scripts for calling the build tools as well as the DLLs for GCC. – esskov Jan 26 '16 at 17:50
  • Following your steps, once I try to actually use theano I get something like "Problem occurred during compilation with the command line below: ...". – user2717954 Apr 14 '16 at 14:24
  • @Daniel Renshaw How to check in windows if i am done with step 1? – Learner Apr 15 '16 at 13:35
  • @SIslam, thats easy, your path enviroment should now have a path to wherever you installed it/bin and when you write g++ or gcc in your cmd window you should see that it is a recognized command – user2717954 Apr 16 '16 at 18:57
  • @Daniel Renshaw what do you think about extending this answer to include Python 3.5? I assume it won't be much of a difference? A question on that appeared [here](http://stackoverflow.com/questions/38129033/how-to-install-theano-for-python-3-5-on-windows-10). – hbaderts Jul 01 '16 at 05:18
  • Similar to @esskov I can vouch that you need to make sure your PATH is correct and in the correct order. After testing multiple solutions, installing mingw, etc, etc, that was not the case for me :) – Victor Sep 28 '16 at 13:14
6

The trick is that YOU NEED TO CREATE AN ENVIRONMENT/WORKSPACE FOR PYTHON. This solution should work for Python 2.7 but at the time of writing keras can run on python 3.5, especially if you have the latest anaconda installed (this took me awhile to figure out so I'll outline the steps I took to install KERAS in python 3.5):

-- CREATE ENVIRONMENT/WORKSPACE FOR PYTHON 3.5:

  1. C:\conda create --name neuralnets python=3.5
  2. C:\activate neuralnets

-- INSTALL EVERYTHING (notice the neuralnets workspace in parenthesis on each line). ACCEPT ANY DEPENDENCIES EACH OF THOSE STEPS WANTS TO INSTALL:

  1. (neuralnets) C:\conda install theano
  2. (neuralnets) C:\conda install mingw libpython
  3. (neuralnets) C:\pip install tensorflow
  4. (neuralnets) C:\pip install keras

-- TEST IT OUT:

(neuralnets) C:\python -c "from keras import backend; print(backend._BACKEND)"

Just remember, if you want to work in the workspace you always have to do:

C:\activate neuralnets

so you can launch Jypiter for example (assuming you also have jypiter installed in this environment/workspace) as:

C:\activate neuralnets
(neuralnets) jypiter notebook

You can read more about managing and creating conda environments/workspaces at the follwing URL: https://conda.io/docs/using/envs.html

Denis
  • 11,796
  • 16
  • 88
  • 150
  • 1
    Please don't post identical answers to multiple questions. Post one good answer, then vote/flag to close the other questions as duplicates. If the question is not a duplicate, *tailor your answers to the question.* – Baum mit Augen Feb 13 '17 at 19:32
3

Adding GPU support is not that much more complicated (although not intuitive)

  1. Install theano as in Daniel Renshaw's answer
  2. Go to the "From Zero to Lasagne" tutorial, and follow it from the Nvidia GPU support (CUDA) section with the following changes:
    • I installed visual studio 2013 community instead of the Windows SDK
    • And .theanorc should be placed in C:\Users\USERNAME
Toke Faurby
  • 5,788
  • 9
  • 41
  • 62
  • I can run a simple gputest, which in fact can grab most of my GPU memory and is aware of cuDNN.... however, when trying to run a script that uses Keras on Theano, it seems that Theano (or perhaps Keras) wants tensorflow, and tensorflow wants Python 3.x rather than 2.7.x... and that's when things just start to break down for me: I've been unable to get over that hurdle. – johnjps111 Dec 07 '16 at 18:42
  • 1
    I am pretty sure it is a Keras thing. What I posted here reference use TensorFlow at all. TF on windows only works with Pyhton 3.5, so install that version if you want TF. **PS** if you don't want Theano to take up so much GPU memory change the `cnmem = X` parameter. If `X<1` then it is the fraction of your GPU memory that is used. if `X>1` it is the absolute amount of space (believe it is mB) that you give it. – Toke Faurby Dec 09 '16 at 13:10
  • Your welcome. **PS** just noticed that I am missing a `doesn't`, as in it should have been *What I posted here **DOESN'T** reference TensorFlow at all*. – Toke Faurby Dec 09 '16 at 20:27
  • 1
    My own stupidity there - my own .keras/.keras.json was telling it to use tensorflow, which is apparently the default now. – johnjps111 Dec 09 '16 at 20:32
0

If you need Theano on python 2.7 and you already installed Anaconda, you can type the following in a command prompt:

conda create -n Python_27 python=2.7.16
conda activate Python_27
conda install numpy=1.12 scipy mkl-service libpython
conda install theano 

It appears that the windows python 2.7 numpy packages don't include the _mklinit patch. Either set the MKL_THREADING_LAYER in your env or update to python 3 which does have patched packages. You can type in your env:

python
import os
os.environ["MKL_THREADING_LAYER"] = "GNU"
illuminato
  • 1,057
  • 1
  • 11
  • 33