0

I'm using Python 2.7, Windows 7, and Keras 1.2.1 (Keras2 seems to be having a lot of compatibility issues with different PC/Python configs, so I was recommened to use 1.2.1) I'm using a script from Practical Deep Learning For Coders, Part 1 Course

import utils; reload(utils)
from utils import plots

The error I"m getting is as below

Problem occurred during compilation with the command line below: "g++" -shared -g -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -DMS_WIN64 -I"c:\python27\lib\site-packages\numpy\core\include" -I"c:\python27\include" -I"c:\python27\lib\site-packages\theano\gof" -L"c:\python27\libs" -L"c:\python27" -o C:\Users\Moondra\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_94_Stepping_3_GenuineIntel-2.7.12-64\lazylinker_ext\lazylinker_ext.pyd C:\Users\Moondra\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_94_Stepping_3_GenuineIntel-2.7.12-64\lazylinker_ext\mod.cpp -lpython27

I can't decipher what this means. Google search brought up a Chinese message board.

It seems to be a g++ problem as the previous warning I got was as follows: WARNING (theano.configdefaults): g++ not available, if using conda:conda install m2w64-toolchain``. Despite installing m2w64-toolchain afterwards, I was continuing to get the same warning.

Moondra
  • 4,399
  • 9
  • 46
  • 104
  • 1
    I'm not sure it's the same problem, because it seems to lack an actual error message.... But, in case it's a g++ issue, you probably need to have visual studio installed, or a compatible C++ compiler. -- See here for the versions you need: https://wiki.python.org/moin/WindowsCompilers – Daniel Möller Apr 26 '17 at 17:13
  • yeah it's a g++ problem as the previous warning I got was as follows: `WARNING (theano.configdefaults): g++ not available, if using conda: conda install m2w64-toolchain`. Despite installing m2w64-toolchain afterwards, I still received the same warning. So I'm guessing it's path problem? – Moondra Apr 26 '17 at 17:22
  • I have Microsoft Visual C++ installed already, as I needed it for some other framework. – Moondra Apr 26 '17 at 17:25
  • You need a specific version of the compiler. For python 2.7, you need C++ V9.0, which matches Visual Studio 2008, is that the version you have? – Daniel Möller Apr 26 '17 at 18:58

2 Answers2

1

Some interesting things I learned while trying to configure theano and keras:

C++/g++

  • Depending on your python version, you have to install a corresponding version of the C++ compiler, or Visual Studio. Ex: Python 2.7 needs C++ 9.0 (Visual Studio 2008). But Python 3.5 needs C++ 14.0 (Visual Studio 2015) -- See here for more: https://wiki.python.org/moin/WindowsCompilers

  • I also had to install MinGW for g++ compilers: https://nuwen.net/mingw.html

  • Even with it correctly installed, you may see an error about hypot. This question shows two possible solutions: g++ error on import of Theano on Windows 7

  • I tried installing everything via Conda, but all calculations were slower than continents moving away from each other. Then I gave up conda and installed everything via standard python. (First python, then numpy, then scipy, then theano, then keras). Not sure if MinGW goes before of after numpy/scipy, but I think it goes before.

BLAS/LAPACK

  • Numpy and theano may warn you that no lapack/blas is installed. For that, I used the numpy and scipy libraries available here, they're great and fast: http://www.lfd.uci.edu/~gohlke/pythonlibs/

  • Another option is installing MKL directly from Intel, before installing numpy and scipy.

Path problems / Invalid Token - ldflags

  • Avoid installing anything, including the MKL, in folders containing spaces in their names! That will definitely confuse theano/numpy.

  • You may get "invalid token" errors if you have spaces in folders, and a ldflags var described in that error. To solve that, either reinstall your mkl libraries in folders without spaces, or configure the .theanorc file in the theano home folder with your [blas] configuration and the ldflags var. (See here: Receive AssertionError while optimizing convolution in theano)

  • Since I wasn't willing to reinstall MKL in another folder, I learned to create symbolic links to windows. (in the answer above)

  • Replace the folders with space in the theano config and also in the numpy config files (__config__.py), you can see its content with np.__config__.show(). (See answer above)

Community
  • 1
  • 1
Daniel Möller
  • 84,878
  • 18
  • 192
  • 214
  • I use Python 3.6 (have 2.7 installed as well) but the notebooks I'm studying from use version 2.7, so was forced to adapt. I plan to install Keras with my 3.6 version, so I hope I don't run into compatibility issues. I seem to have Visual Studio 2008 installed. – Moondra Apr 26 '17 at 19:38
  • I suggest you use python 3.5 instead (I haven't read anywhere that keras/theano/tensorflow are compatible with 3.6, but they do specify 3.5). For python 3.5, you'll need C++ 14.0 (VS 2015). – Daniel Möller Apr 26 '17 at 19:40
0

I solved the problem.

I reinstalled Anaconda. And then via command line I wrote conda install m2w64-toolchain This time I didn't get a message stating that m2w64 was already installed. I'm assuming it was a path issue and this time reinstalling everything from the start also created a new path?

Moondra
  • 4,399
  • 9
  • 46
  • 104