Keras installation issue on windows 10

573 views
Skip to first unread message

Matthew Takao

unread,
Nov 30, 2016, 8:08:34 AM11/30/16
to Keras-users
I'm stumbling through the long installation process of Keras, and I'm starting to get overwhelmed. I think the clarity of the installation process for Windows users could be greatly improved. (http://deeplearning.net/software/theano/install_windows.html#install-windows

There are several references to Python 2.7 with alternative options for Python 3.5, so I'm concerned 3.5 might not be supported in this Windows installation process, specifically regarding the CUDA section. 

My system is: Windows 10, Python 3.5.2

Currently, I can import Theano with seemingly no issue. Going through this code (from http://deeplearning.net/software/theano/install_windows.html#install-windows) seems to work perfectly:

import numpy as np
import time
import theano
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')
mf
= theano.function([X,Y],X.dot(Y))
t_start
= time.time()
tAB
= mf(A,B)
t_end
= time.time()
print("NP time: %f[s], theano time: %f[s] (times should be close when run on CPU!)" %(
                                           np_end
-np_start, t_end-t_start))
print("Result difference: %f" % (np.abs(AB-tAB).max(), ))


I've followed the Windows installation guide to the best of my ability.

But honestly, even going through the guide several times I am still not sure what core components are necessary, especially with the inclusion of the alternative methods. For example, the wording for the Anaconda alternative suggests that simply going through those instructions would provide all dependencies for keras. But I still get the error listed below. 

Between CUDA, Microsoft Visual Studio, GCC, Scientific Python, WinPython, Theano, Windows paths, MSYS, MinGW, MSVC, gendef, nvcc, BLAS, etc. it's REALLY difficult to know what is happening. 

OK, here is where I am stuck specifically. When I try to import keras, I get this:

import keras
Using Theano backend.
Traceback (most recent call last):
 
File "<pyshell#3>", line 1, in <module>
   
import keras
 
File "C:\Python\lib\site-packages\keras\__init__.py", line 4, in <module>
   
from . import engine
 
File "C:\Python\lib\site-packages\keras\engine\__init__.py", line 10, in <module>
   
from .training import Model
 
File "C:\Python\lib\site-packages\keras\engine\training.py", line 24, in <module>
   
from .. import callbacks as cbks
 
File "C:\Python\lib\site-packages\keras\callbacks.py", line 15, in <module>
   
from pkg_resources import parse_version
 
File "C:\Python\lib\site-packages\pkg_resources\__init__.py", line 34, in <module>
   
import plistlib
 
File "C:\Python\lib\plistlib.py", line 65, in <module>
   
from xml.parsers.expat import ParserCreate
 
File "C:\Python\lib\xml\parsers\expat.py", line 4, in <module>
   
from pyexpat import *
ImportError: DLL load failed: The specified module could not be found.

Now, I've googled terms for this for about an hour with no good results. Does anyone know what specifically I might be missing? 


Tomasz Melcer

unread,
Nov 30, 2016, 9:47:33 AM11/30/16
to Matthew Takao, Keras-users
On 11/30/2016 02:08 PM, Matthew Takao wrote:
> I'm stumbling through the long installation process of Keras, and I'm
> starting to get overwhelmed. I think the clarity of the installation
> process for Windows users could be greatly improved.
> (http://deeplearning.net/software/theano/install_windows.html#install-windows)

As an outsider observing what kind of problems Windows developers have,
my main thought here is that if it was easy to make the installation
process simpler, it would have been done years ago.

I am pretty sure the relevant parties do accept patches though.


> importkeras
> UsingTheanobackend.
> […]
> File"C:\Python\lib\plistlib.py",line 65,in<module>
> fromxml.parsers.expat importParserCreate
> File"C:\Python\lib\xml\parsers\expat.py",line 4,in<module>
> frompyexpat import*
> ImportError:DLL load failed:Thespecified modulecould notbe found.
>
> Now, I've googled terms for this for about an hour with no good results.
> Does anyone know what specifically I might be missing?

I don't use Python on Windows, but it looks like you have some problem
with the base python installation. Do you have multiple python
installations?

For a simple test-case, try running the `from xml.parsers.expat import
ParserCreate` command in a fresh Python interpreter. It ought to work
with no other libraries installed.


--
Tomasz Melcer

mustg...@gmail.com

unread,
Nov 30, 2016, 10:01:11 AM11/30/16
to Keras-users
Its a huge pain. Please look at my post on how i got it installed. I cant remember if I included moving 3 dll files from mingw ibtk the dll in the list of instructions or not (you need to - see 0 to lasagne for which dlls) but I got it to work with wibdows 7 and pythin 3.5. It took the help of knowledgable progammer who helped with the paths and a lot of screwing around and days of google searching. I posted it on the lasagne users nd theano users i believe. Maybe here too.

Isaac Gerg

unread,
Nov 30, 2016, 2:06:16 PM11/30/16
to Keras-users
http://www.gergltd.com/home/2016/04/installing-theano-in-windows-7-with-python-3-4/

you can install keras via pip or pull from github and direct your sys.path to the directory.

Matthew Takao

unread,
Nov 30, 2016, 6:10:30 PM11/30/16
to Keras-users, taka...@gmail.com
Hi Tomasz, thanks for the reply. I get the same DLL error, so I'll look into reinstalling Python in general I guess??
Message has been deleted

Mustg Oplay

unread,
Nov 30, 2016, 9:40:02 PM11/30/16
to Keras-users
I cant copy the link for some reason. If you search on theano users group for "pycharm windows" you'll see my post that shows how i got it installed on windows with mkl.

titu...@gmail.com

unread,
Dec 3, 2016, 8:35:21 AM12/3/16
to Keras-users
I've tried installing Theano onto Windows 10 with Python 3.5 to no avail. This may have changed recently, but I haven't been successful in setting up theano with 3.5 on windows.

I have a guide for setting up Theano with CUDA GPU (https://github.com/titu1994/Neural-Style-Transfer/blob/master/Guide.md) (please see the very last sections). It details every step required to install Theano with GPU support on Windows. Note you can replace Cuda 7.5 with 8 everywhere and it will still work.

You may not necessarily need to install pillow or h5py but I recommend installing them anyway since they are required for many image libraries and weight saving/loading in Keras.

Mustg Oplay

unread,
Dec 3, 2016, 2:56:45 PM12/3/16
to Keras-users, titu...@gmail.com
Titu,  Very nice install instructions.

It may be because you are using openblas.  I couldn't get that to work either with 3.5 but mkl works with theano and 3.5 on windows 7 but I don't have a gpu. Someone helped me with the paths (wish I had seen your install instructions), but the rest was figured out through a lot of googling.

Here's the output of check_blas.py:

Some Theano flags:
    blas
.ldflags= -LC:\Anaconda3\envs\corrnet\Library\bin -lmkl_rt
    compiledir
= C:\Users\Anon\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_42_Stepping_7_GenuineIntel-3.5.2-64
    floatX
= float32
    device
= cpu
Some OS information:
    sys
.platform= win32
    sys
.version= 3.5.2 | packaged by conda-forge | (default, Jun 30 2016, 17:50:59) [MSC v.1900 64 bit (AMD64)]
    sys
.prefix= C:\Anaconda3\envs\ainn
Some environment variables:
    MKL_NUM_THREADS
= None
    OMP_NUM_THREADS
= None
    GOTO_NUM_THREADS
= None

Numpy config: (used when the Theano flag "blas.ldflags" is empty)
blas_mkl_info
:
    include_dirs
= ['C:/Anaconda3/envs/ainn\\Library\\include']
    libraries
= ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll']
    library_dirs
= ['C:/Anaconda3/envs/ainn\\Library\\lib']
    define_macros
= [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
openblas_lapack_info
:
  NOT AVAILABLE
blas_opt_info
:
    include_dirs
= ['C:/Anaconda3/envs/ainn\\Library\\include']
    libraries
= ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll']
    library_dirs
= ['C:/Anaconda3/envs/ainn\\Library\\lib']
    define_macros
= [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
lapack_opt_info
:
    include_dirs
= ['C:/Anaconda3/envs/ainn\\Library\\include']
    libraries
= ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll']
    library_dirs
= ['C:/Anaconda3/envs/ainn\\Library\\lib']
    define_macros
= [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
lapack_mkl_info
:
    include_dirs
= ['C:/Anaconda3/envs/ainn\\Library\\include']
    libraries
= ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll']
    library_dirs
= ['C:/Anaconda3/envs/ainn\\Library\\lib']
    define_macros
= [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
Numpy dot module: numpy.core.multiarray
Numpy location: C:\Anaconda3\envs\ainn\lib\site-packages\numpy\__init__.py
Numpy version: 1.11.2

We executed 10 calls to gemm with a and b matrices of shapes (5000, 5000) and (5000, 5000).

Total execution time: 35.04s on CPU (with direct Theano binding to blas).

Try to run this script a few times. Experience shows that the first time is not as fast as followings calls. The difference is not big, but consistent.

Process finished with exit code 0


And here's my .theanorc:

[global]
force_device
= True
device
= cpu
floatx
= float32
warn_float64
= warn

[blas]
ldflags
= -LC:\Anaconda3\envs\corrnet\Library\bin -lmkl_rt

[gcc]
cxxflags
= -LC:\Anaconda3\envs\corrnet\Library\include -LC:\Anaconda3\envs\corrnet\Library\lib -lm

[nvcc]
flags
=--use-local-env --cl-version=2010 -D_FORCE_INLINES
fastmath
= True


And my nvcc.profile file in case they help you:


TOP              
= $(_HERE_)/..

NVVMIR_LIBRARY_DIR
= $(TOP)/nvvm/libdevice

PATH            
+= $(TOP)/open64/bin;$(TOP)/nvvm/bin;$(_HERE_);$(TOP)/lib;

INCLUDES        
+=  "-I$(TOP)/include" $(_SPACE_)
INCLUDES
+= "-I$(TOP)/include" "-I$(TOP)/include/cudart" "-IC:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include" $(_SPACE_)

LIBRARIES        
=+ $(_SPACE_) "/LIBPATH:$(TOP)/lib/$(_WIN_PLATFORM_)"

CUDAFE_FLAGS    
+=
OPENCC_FLAGS    
+=
PTXAS_FLAGS    
+=

Mustg Oplay

unread,
Dec 19, 2016, 1:34:50 AM12/19/16
to Keras-users, titu...@gmail.com
One last post on this.  I got a new computer with a gpu and it took forever but I figured it out.  I've written explicit instructions with the minimum number of files I needed to get things working:


Hope this helps.
Reply all
Reply to author
Forward
0 new messages