Install Theano under Anaconda3 Python 3.5

August 11, 2016
By

(This article was originally published at SAS Programming for Data Mining, and syndicated at StatsBlogs.)

Update on 2017/01/05:

With the release of Anaconda3-4.2.0 in September 2016, users are able to install mingw and libpython under conda, which makes  using Theano and keras in Python3.5 much easier.
Here are the simple steps:
1. Install Anaconda3-4.2.0. I used their Anaconda3-4.2.0-Windows-x86_64.exe installer, MD5=0ca5ef4dcfe84376aad073bbb3f8db00
2. In your Anaconda Prompt, execute : >>conda install -c anaconda mingw libpython
3. Install Theano and keras. I used their github repository
4. Remove the following statements from __init__.py file under Theano's installation folder:

if sys.platform == 'win32' and sys.version\_info[0:2] == (3, 5):
      raise RuntimeError( "Theano do not support Python 3.5 on Windows. Use Python 2.7 or 3.4.")

5. Input the following statement in Environment Variable under system settings:

THEANO_FLAG=floatX=float32,device=cpu,blas.ldflags=-LC:\\openblas -lopenblas

Adding GPU capability follows the general GPU installation rule as well.

Now you are good to go, enjoying Theano backed deep learning and  Python35
=======================
As of writing, Deep Learning package Theano can't be installed under Python 3.5, which causes some problems with my project. ruslanagit provided a viable solution that works for me under Windows 10.

For convenience, I copied his solution below:

Well, the main problem with Python 3.5 on windows, I guess, is that mingw and libpython are not available (not complied with Python 3.5), so you cannot run $ conda install mingw libpython step.

So you either need to downgrade to Python 3.4 (was not an option for me) and then follow standard instructions for installing Theano on Windows, or make a few tricks to make theano work with Python 3.5. For me the following steps worked on Windows 10 with Anaconda3 and Python 3.5:

  • Install mingw from https://sourceforge.net/projects/mingw-w64/ 
  • Add the bin directory of mingw to PATH, and make sure there is no other gcc compiler in PATH (i.e. TDM-GCC is not there). 
  • In .theanorc file add 
 [gcc]
cxxflags = -shared -I"[TDM-GCC path]\include" -I"[TDM-GCC path]\x86_64-w64-mingw32\include"

You should update paths to TDM-GCC according to your system. Note, that TDM include directory is required, since the compilation will fail with mingw include directories for python 3.5 (I think they would work for Python 2, but I am not 100% sure)
  • Create libpython35.a manually and copy it to appropriate directory. For example: 
    • Create temp directory 
    • Copy python35.dll (I took it from Anaconda3 folder) into created directory 
    • Navigate into created directory 
    • Run: gendef python35.dll 
    • Run: dlltool --dllname python35.dll --def python35.def --output-lib libpython35.a 
    • Copy libpython35.a into Anaconda3\libs 
    • All other installations/configurations were done as described in the guide for installaing Theano on Windows.



Please comment on the article here: SAS Programming for Data Mining

Tags: ,


Subscribe

Email:

  Subscribe