Introduction
It seems these instruction are deprecated as the preferred method to install Theano is using Anaconda, as described on the page Converting to the new gpu back end(gpuarray).
In a previous article, I described a procedure to install Keras and Theano on Windows 10. The main downside of this procedure is that you had to downgrade to Python 3.4. This tutorial is an improved version which allows you to make Theano and Keras work with Python 3.5 on Windows 10.
Unless stated otherwise, all install options are left to their default/recommended values. In case you change installation paths, make sure you also change them in all subsequent commands.
Installing CUDA
This step is optional but highly recommended for NVidia card owners as it massively speeds up Theano by allowing it to use the GPU:
- Download and install Visual Studio Community 2013 update 5. This is a direct link which may not work in the future as your are now required to create a Microsoft account to download old versions of Visual Studio. Do not install Visual Studio 2015 as latest versions are not compatible with CUDA 8. Open VS2013 to see if it’s working.
- Add C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin to the PATH.
- Download and install CUDA 8.0, you have to create a free NVidia account to download the file. Open the samples directory C:\ProgramData\NVIDIA Corporation\CUDA Samples\v8.0 and then the Samples_vs2013.sln file. Run any project to see if CUDA is working, for instance, 5_Simulations/oceanFFT. Right click on it, then click on Debug>Start new instance. Accept to build the project, then you should see a simulated ocean surface.
- The CUDA installation may have downgraded your NVidia drivers, you can upgrade them again.
Installing Theano
- Download and install Anaconda 64 bits with Python 3.5 for Windows. Open a command line and check that Python is working and that it is indeed the Anaconda python 3.5 version.
- Download and extract MinGW x86_64-5.4.0-release-posix-seh-rt_v5-rev0.7z. Make sure you’re not using a newer version as it won’t work with Theano.
- Add MinGW bin directory to the PATH. For instance, if you extracted MinGW on C: , then add C:\x86_64-5.4.0-release-posix-seh-rt_v5-rev0\mingw64\bin to the PATH.
- Open a new command prompt (to take into account the modification to the PATH) and type:
1234cd %USERPROFILE%\Anaconda3\libsgendef ..\python35.dlldlltool --as-flags=--64 -m i386:x86-64 -k --output-lib libpython35.a --input-def python35.defdel python35.def - Download and install Git for Windows.
- In the command prompt type:
123456cd %USERPROFILE%\Anaconda3\Lib\site-packagesgit clone git://github.com/Theano/Theano.gitcd Theanopython setup.py developcd %USERPROFILE%type NUL > .theanorc - Open the explorer and type in the address bar %USERPROFILE%, open the .theanorc file and add the following lines:
123456[global]floatX = float32device = gpu[nvcc]compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
I assume you installed CUDA, if it is not the case, you have to replace device = gpu by device = cpu . If you have more than one GPU, you can also specify which one you want to use using gpu1 or gpu2 etc. - If your Windows username contains a space or any unusual character or if you want Theano to put its temporary files to a specific place (they can use several Gb of disk space) then add
base_compiledir=C:\theano_compiledir under the
[global] section of your .theanorc file. Your .theanorc file should now contain:
1234567[global]floatX = float32device = gpubase_compiledir=C:\theano_compiledir[nvcc]compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin - Now it s time to test if Theano is working properly. Copy the following code into a file and run it in the command line.
12345678910111213141516171819202122from theano import function, config, shared, sandboximport theano.tensor as Timport numpyimport timevlen = 10 * 30 * 768 # 10 x #cores x # threads per coreiters = 1000rng = numpy.random.RandomState(22)x = shared(numpy.asarray(rng.rand(vlen), config.floatX))f = function([], T.exp(x))print(f.maker.fgraph.toposort())t0 = time.time()for i in range(iters):r = f()t1 = time.time()print("Looping %d times took %f seconds" % (iters, t1 - t0))print("Result is %s" % (r,))if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):print('Used the cpu')else:print('Used the gpu')
If everything s OK, this code will display something like that:
123456Using gpu device 0: GeForce GTX 960 (CNMeM is disabled, CuDNN not available)[GpuElemwise{exp,no_inplace}(<CudaNdarrayType(float32, vector)>), HostFromGpu(GpuElemwise{exp,no_inplace}.0)]Looping 1000 times took 0.5765759944915771 secondsResult is [ 1.23178029 1.61879349 1.52278066 ..., 2.20771813 2.299677611.62323296]Used the gpu
Installing Keras
- In a command prompt, type:
1234cd "%USERPROFILE%\Anaconda3\Lib\site-packages"git clone git://github.com/fchollet/keras.gitcd keraspython setup.py develop - As Keras uses TensorFlow as the default backend, we have to change that for Theano. Open a command line and type:
12cd %USERPROFILE%md .keras - Create a file named
keras.json in
%USERPROFILE%/.keras and add the following lines:
123456{"floatx": "float32","epsilon": 1e-07,"image_dim_ordering": "th","backend": "theano"} - Now it s time to test if Keras is working properly. Copy the following code into a file and run it in the command line.
123456789101112131415161718192021222324252627282930313233343536373839from keras.models import Sequentialfrom keras.layers import Dense, Dropout, Activationfrom keras.optimizers import SGDimport numpy as npdata_dim = 20nb_classes = 4model = Sequential()# Dense(64) is a fully-connected layer with 64 hidden units.# in the first layer, you must specify the expected input data shape:# here, 20-dimensional vectors.model.add(Dense(64, input_dim=data_dim, init='uniform'))model.add(Activation('tanh'))model.add(Dropout(0.5))model.add(Dense(64, init='uniform'))model.add(Activation('tanh'))model.add(Dropout(0.5))model.add(Dense(nb_classes, init='uniform'))model.add(Activation('softmax'))model.compile(loss='categorical_crossentropy',optimizer='sgd',metrics=["accuracy"])# generate dummy training datax_train = np.random.random((1000, data_dim))y_train = np.random.random((1000, nb_classes))# generate dummy test datax_test = np.random.random((100, data_dim))y_test = np.random.random((100, nb_classes))model.fit(x_train, y_train,nb_epoch=20,batch_size=16)score = model.evaluate(x_test, y_test, batch_size=16)
If everything is working properly you should see (it can take several minutes on the first run):
1234Using Theano backend.Using gpu device 0: GeForce GTX 960 (CNMeM is disabled, CuDNN not available)[Lots of Epoch N/20 with loss and accuracy measures] - To be able to draw graph representation of models, there are two more dependencies to install. In the command prompt, type:
12conda install graphvizpip install git+https://github.com/nlhepler/pydot.git - Pydot may have trouble finding the path to GraphViz. Open the file
__init__.py in
%USERPROFILE%\Anaconda3\Lib\site-packages\pydot and add
1234567elif os.path.exists(os.path.join(path, prg + '.bat')):if was_quoted:progs[prg] = '"' + os.path.join(path, prg + '.bat') + '"'else:progs[prg] = os.path.join(path, prg + '.bat')success = True
just after
1234567elif os.path.exists(os.path.join(path, prg + '.exe')):if was_quoted:progs[prg] = '"' + os.path.join(path, prg + '.exe') + '"'else:progs[prg] = os.path.join(path, prg + '.exe')success = True
Troubleshooting
If you encounter any error message during the installation and tests, check that your PATH is clean. Open a new command prompt and type:
- This command should return the path where you installed Anaconda:
1where python - All these command should return the path where you extracted MinGW:
1234where gccwhere g++where gendefwhere dlltool - This command should return the path of the bin folder of your VS2013 installation:
1where cl - This command should return the path where you installed CUDA (if you use it):
1where nvcc - Older versions of Theano were not supposed to work with Python 3.5. If you encounter any problem, you have to bypass this limitation (without any know problem) by editing the file
__init__.py located in
%USERPROFILE%\Anaconda3\lib\site-packages\theano\theano\ and delete the lines:
123if 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.")
Conclusion
Now you should be ready to do amazing stuff with Keras and Theano. If you want to make your networks run faster, you should check my article on how to use CuDNN and CNMeM with Theano.
Jeet
Can I use Theano and other mentioned (above) packages even if I don’t have a GPU in my system?
Fabien Tencé
Hi Jeet,
You can of course use Keras and Theano on CPU. It will be slower but it will work.
To do so, you have to skip the CUDA part and specify
device = cpu
in the .theanorc file.You can also look at my article on CNMeM and CuDNN. There is a section on OpenBLAS (skip the rest). Linking Theano to OpenBLAS should speed up a bit networks on CPU. I’m not sure if you need the mingw64_dll.zip, as you already put MinGW in the PATH.
Lucas
Thank you so much for this detailed tutorial. Everything seems to be working fine. One of the few straightfoward oob tutorials. Thanks!
Gilsinia
thank you. Very helpful 🙂
Kyle
Thanks for the guide. I’m getting “ImportError: No module named ‘tensorflow'” when I try to run testKeras.py. Do you know if there’s a workaround for this or some way to get tensorflow on Windows?
Fabien Tencé
Hi Kyle,
Keras has changed its default backend from Theano to Tensorflow not too long ago. You have to edit the file keras.json in %userprofile%/.keras/ and change backend to “theano” and image_dim_ordering to “th”. I’ll add that to the article, thanks for your feedback.
As Tensorflow cannot use the GPU on Windows for now, I’d advise against installing it and using it with Keras. Even if you’re using the CPU, Tensorflow on Windows is still not very well supported.
Kyle
Thanks Fabien, it’s working now!
AndreiCh
Starting from TensorFlow 0.12 it is possible to run it on Windows 7/ 10 with GPU
https://developers.googleblog.com/2016/11/tensorflow-0-12-adds-support-for-windows.html
Enjoy
Edit by Fabien: I’m putting your link to your blog post on a easier and nicer way to install Keras, Theano and TensorFlow here. If someone has trouble installing these, you should give it a try.
Fabien Tencé
Hi Andrei,
Thanks for the info. I’ll take a look and see if it’s worth switching from Theano to TensorFlow.
AndreiCh
Thank you Fabien. It is very kind of you.
Niv
Hi,
Thanks for this great tutorial. I’ve followed all the steps to install theano but for some reason it does not import. g++ reports that “mod.cpp” and “lazylinker_ext.pyd” are missing (which is actually true only for lazylinker.pyd). How can I fix this?
Fabien Tencé
Hi Niv,
It’s hard to tell, here’s a few guesses:
libpython35.a
in%USERPROFILE%\Anaconda3\libs
?where g++
return the path where you extracted MinGW?Niv
Yes to all questions… can it be because of spaces in the user name?
Fabien Tencé
Good idea, try adding the following line to your .theanorc file under the
[global]
section:base_compiledir=c:\theano_compiledir
This directory will be created and used by Theano to compile stuff. By default it uses the %LOCALAPPDATA%\Theano directory which, in your case, contains a space.
edit: I can confirm this, having a space in Theano’s compile directory gave me the same error. I updated the article accordingly, thanks.
Niv
Hi,
Thanks for the solution. I actually managed to overcome this problem in a different way. The failure was in a cmd command that call g++. Adding quotation marks around the path for mod.cpp and lazylinker_ext.pyd (in this cmd command) seems to solve the problem. The relevant code is around line 2278 in cmodule.py, at %USERPROFILE%\Anaconda3\Lib\site-packages\Theano\theano\gof.
Do you think that this issue may still cause problems in the future? should I change the default compile directory in any case?
Fabien Tencé
It shouldn’t cause any problem until you update Theano.
Priya
Hello,
I am trying to install theano and keras according to the tutorial. I followed all the steps exactly as mentioned. However when I run the testtheano.py, I get import error: No module named ‘theano’.
I am using spyder(python 3.5). As I am still new to this field any help provided will be very much appreciated!
Fabien Tencé
Hi Priya,
Maybe there is another version of Python installed and you’re running it. Open a command prompt and run
where python
to make sure you’re running the Python version which comes with your Anaconda install.Also double check that in the
%USERPROFILE%\Anaconda3\Lib\site-packages
there is atheano
directory.Katarina
Hi,
thanks for this tutorial. I am stuck at this step. Any guesses what I am doing wrong? Thanks.
C:\Program Files\Anaconda3\libs>gendef ..\python35.dll
* [..\python35.dll] Found PE+ image
* failed to create python35.def …
Fabien Tencé
Hi Katarina,
It seems that gendef can’t create the file, maybe because you do not have the permission to write the file? Try copying the python35.dll file in another directory and run the commands and copy back the resulting libpython35.a in the libs directory. You can also try to open the command prompt with admin rights and run the commands.
NILADRI GARAI
Run any project to see if CUDA is working, for instance, 5_Simulations/oceanFFT.
I am getting the following error.
access to path ‘C:\ProgramData\NVIDIA Corporation\CUDA Samples\v8.0\7_CUDALibraries\nvgraph_SSSP\nvgraph_SSSP_v2013.vcxproj’ is denied
Fabien Tencé
Hi Niladri,
It seems to me that you do not have the permission to modify files in ProgramData. Try copying the whole CUDA Samples directory to %USERPROFILE% and test from there.
Patrick
Hello,
I followed the tutorial and wantet to test theano, but I always get an error and have no idea how to fix it:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\crtdefs.h(10): fatal error C1083: Cannot open include file: ‘corecrt.h’: No such file or directory
ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: (‘nvcc return status’, 2, ‘for cmd’, ‘nvcc -shared -O3 -use_fast_math -Xlinker …….
WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not available (error: cuda unavailable)
Something seems to be off with using the GPU, because it just mentions that it used the cpu instead (The ocean simulation runs without problems).
Fabien Tencé
Hi Patrick,
It seems that there is something wrong with your configuration. The error message refers to “Microsoft Visual Studio 14.0” which is the 2015 version. MVS 2015 is not compatible with CUDA.
My guess it that Theano tries to use MVS 2015 to compile its CUDA code and it fails. Just a shot in the dark, try adding:
[nvcc]
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
to your .theanorc file.
Patrick
Thank you! It works like a charm^^
Jaume
Thanks Fabien for this (very) useful tutorial!
Manasa
Hi. Thank you so much for this tutorial. I was able to get theano working however when I run the code to test if keras is installed it tells me
ImportError: No module named ‘keras.models’
I am trying to run it in spyder IDE. Could you please help me out.
Fabien Tencé
Hi Manasa,
I’m not familiar with Spyder IDE. Open a command prompt and type
python
thenimport keras
andimport keras.models
:ssl
Had the same error, Spyder just had to be restarted after installation of the package, then it worked like a charm. [Courtesy Jaco’s answer here: http://stackoverflow.com/questions/35019278/spyder-ide-for-python-not-recognizing-path-to-packages ]
Thanks Fabien for the really helpful step-by-step tutorial!
Fabien Tencé
Hi,
Thanks for the info!
Alabastor95
Hi there!
I’m quite new to this whole programming stuff: could you tell me, which path do you mean under ‘PATH’? What am i supposed to do?
thx 🙂
Fabien Tencé
Hi!
PATH is an environment variable. You can modify it following these steps.
You can modify the PATH variable for your user account or for all the accounts (under the system variables). If there is a single account on your computer, it doesn’t matter which PATH you modify but I advise you to modify your user PATH only.
Yossi
Hi Fabien,
thank you for this tutorial.
Understand from your post that Visual Studio 2013 is required as part of Theano installation. I don’t have Visual Studio installed in my computer.
1. Do you have any work around?
2. I am using Windows 7 (64bit). Is there any changes in your guide lines if the OS is Windows 7?
Thank you.
Fabien Tencé
Hi Yossi,
Visual Studio is only required if you want to use CUDA. There is a download link to VS 2015 update 5 in the relevant section, you should use that to install it.
As for Windows 7, I don’t know if there is any change to be made. I think it should work without any change but I’m not 100% sure.
You’re welcome.
Jaafar Ben-Abdallah
Thank you Fabien for this excellent and straightforward tutorial. I’ve been looking for this for a while now and you just delivered a clear and easy to follow process. Now onto training some DNNs…
Keerthimanu Gattu
I am getting No module named ‘theano’ when running testTheano.py.
One thing I suspect is my theanorc file was empty when I opened it to append the lines mentioned in the tutorial above.
Fabien Tencé
Hi,
It’s hard to tell why it’s not working. Are you using an IDE? Did you restarted it? Are you sure you are running the Anaconda version of Python?
Soren Pallesen
Hi there, thanks good stuff – works like a charm !
However i want to upgrade Theano to the lastest bleeding edge version – do you have any tips for a safe way to do this?
Best regards
Fabien Tencé
Hi Soren,
The best way to do this is:
cd %USERPROFILE%\Anaconda3\Lib\site-packages\Theano
git stash
git pull
git stash pop
python setup.py develop
The
git stash
commands allows you to keep the modifications you made to the code so you don’t have to edit again__init__.py
.You can do he same with Keras, just replace the first command by
cd %USERPROFILE%\Anaconda3\Lib\site-packages\keras
. You don’t need thegit stash
commands if you didn’t modify any files in Keras.Soren Pallesen
Wow thanks !!! I was quite nervous and looking for a way that does not skrew up the installation !
Pavel
Hi Fabien!
I’m stuck at testing Theano. Something doesn’t work properly. I tested paths as you suggested but it still throws out the following error. and I have no idea what to do next. Can you please suggest anything?
Microsoft Windows [Version 10.0.14393]
(c) Корпорация Майкрософт (Microsoft Corporation), 2016. Все права защищены.
C:\Users\Asus>where python
C:\Users\Asus\Anaconda3\python.exe
C:\Users\Asus>where gcc
C:\mingw64\bin\gcc.exe
C:\Users\Asus>where g++
C:\mingw64\bin\g++.exe
C:\Users\Asus>where gendef
C:\mingw64\bin\gendef.exe
C:\Users\Asus>where dlltool
C:\mingw64\bin\dlltool.exe
C:\Users\Asus>python testTheano.py
Traceback (most recent call last):
File “C:\Users\Asus\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py”, line 75, in
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\Asus\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py”, line 92, in
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\Asus\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py”, line 1784, in _try_compile_tmp
os.remove(exe_path + “.exe”)
PermissionError: [WinError 32] process cannot access the file, because the file is used by another process: ‘C:\\Users\\Asus\\AppData\\Local\\Temp\\try_march_v8u8xl9n.exe’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “testTheano.py”, line 7, in
from theano import function, config, shared, sandbox
File “C:\Users\Asus\Anaconda3\lib\site-packages\theano\theano\__init__.py”, line 67, in
from theano.compile import (
File “C:\Users\Asus\Anaconda3\lib\site-packages\theano\theano\compile\__init__.py”, line 10, in
from theano.compile.function_module import *
File “C:\Users\Asus\Anaconda3\lib\site-packages\theano\theano\compile\function_module.py”, line 21, in
import theano.compile.mode
File “C:\Users\Asus\Anaconda3\lib\site-packages\theano\theano\compile\mode.py”, line 10, in
import theano.gof.vm
File “C:\Users\Asus\Anaconda3\lib\site-packages\theano\theano\gof\vm.py”, line 659, in
from . import lazylinker_c
File “C:\Users\Asus\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py”, line 125, in
args = cmodule.GCC_compiler.compile_args()
File “C:\Users\Asus\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py”, line 2088, in compile_args
default_compilation_result, default_execution_result = try_march_flag(GCC_compiler.march_flags)
File “C:\Users\Asus\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py”, line 1856, in try_march_flag
flags=cflags, try_run=True)
File “C:\Users\Asus\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py”, line 2188, in try_compile_tmp
comp_args)
File “C:\Users\Asus\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py”, line 1789, in _try_compile_tmp
err += “\n” + str(e)
TypeError: can’t concat bytes to str
C:\Users\Asus>
Fabien Tencé
Hi Pavel,
You seem to have a problem with lazylinker. Niv had the same kind of problem. You can try to add the following line to your
.theanorc
file under the[global]
section:base_compiledir=c:\theano_compiledir
Also make sure your current user can write to this directory.
Pavel
Sorry Fabien. This doesn’t seem to change anything. It still produces the same errors
Pavel
Hi Fabien!
I managed to succeed by following this instruction:
http://simranmetric.com/installing-theano-on-windows-10-python-3-5/
but using your bundle of mingw. The version of migw provided there doesn’t work. That said, Theano throws out some deprecation warnings upon import
but your test file worked out correctly.
No thinking about how to install the same for my Python 2.7 env within my root python 3.5
Fabien Tencé
Hi Pavel,
I’m glad you managed to install Theano but I don’t understand why the other tutorial worked for you. It seems to me that there are very few differences. Do you have any idea how it solved your problem? Is it the use of pip to install Theano? Or the use of CUDA 7.5?
Julian S.
Hi Pavel,
are you using McAffe antivirus?
I got the installation running until I updated the antivirus software. Try to deactivate the real time analysis feature in order to make your installation run.
Thank you very much Fabien for your complete and detailed explanation!
HTH
Julian S.
Soren Pallesen
Hi again Fabien,
Im looking for some training benchmarks on Keras, know of any good ones?
Preferably :
1) with knows/public datasets
2) CPU vs GPU
3) LTSM networks
Best regards
Soren
Fabien Tencé
Hi Soren,
I haven’t heard of any benchmark, sorry. There are so many factors (hardware and software) that can influence the results, it is difficult to compare. As a rule of thumb, GPU is almost always faster than CPU, consider CPU only for very specific tasks (requiring high precision for example). I don’t have any experience in LTSM, so I can’t help you there.
Nghia
It does not work for me. Here is the error:
Traceback (most recent call last):
File “C:\Users\Win10Home\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py”, line 75, in
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\Win10Home\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py”, line 92, in
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “D:\googleDrive\code\Theano\test.py”, line 8, in
import theano.tensor as T
File “C:\Users\Win10Home\Anaconda3\lib\site-packages\theano\theano\__init__.py”, line 70, in
from theano.compile import (
File “C:\Users\Win10Home\Anaconda3\lib\site-packages\theano\theano\compile\__init__.py”, line 10, in
from theano.compile.function_module import *
File “C:\Users\Win10Home\Anaconda3\lib\site-packages\theano\theano\compile\function_module.py”, line 21, in
import theano.compile.mode
File “C:\Users\Win10Home\Anaconda3\lib\site-packages\theano\theano\compile\mode.py”, line 10, in
import theano.gof.vm
File “C:\Users\Win10Home\Anaconda3\lib\site-packages\theano\theano\gof\vm.py”, line 659, in
from . import lazylinker_c
File “C:\Users\Win10Home\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py”, line 127, in
preargs=args)
File “C:\Users\Win10Home\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py”, line 2323, in compile_str
(status, compile_stderr.replace(‘\n’, ‘. ‘)))
Exception: Compilation failed (return status=1): D:\theano_compiledir\compiledir_Windows-10-10.0.14393-SP0-Intel64_Family_6_Model_78_Stepping_3_GenuineIntel-3.5.2-64\lazylinker_ext\mod.cpp:1:0: sorry,
unimplemented: 64-bit mode not compiled in
. #include
. ^
.
Nghia
Here is new my .theanorc, and it worked somehow.
###
[global]
floatX = float32
device = gpu
base_compiledir=D:\theano_compiledir
cxx = C:\x86_64-5.4.0-release-posix-seh-rt_v5-rev0\mingw64\bin\g++.exe
###
But I got another error:
Using gpu device 0: GeForce 940MX (CNMeM is disabled, cuDNN not available)
Traceback (most recent call last):
File “D:\code\Theano\test.py”, line 16, in
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
NameError: name ‘shared’ is not defined
Here is the line 16: x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
Fabien Tencé
Hi Nghia,
It seems you have the same problem as Pavel. I’ll investigate and report back with what I found. I suspect it is specific to the latest version of Theano but I have to check.
edit: Updated to the last version of Theano and it’s working like a charm. The problem is specific to your configuration.
I notice you didn’t remove the line in
__init__.py
astheano.compile import
is line 70 only in the original file. What version of Python do you use? If you’re not using Python 3.5, either update it or do the gendef/dlltool step with your version of Python (maybe python34?).Raph
Hi Fabien,
I have been trying to install Theano for 3days now, by following all your steps. I tried everything, I even restored W10 to be sure there is no other application which could cause problems . But it’s still not working , when I come to the “python setup.py install” step I get this message in the end:
“UnicodeEncodeError: ‘ascii’ codec can’t encode character ‘\xeb’ in position 16: ordinal not in range(128)”.
I have tried a lot of solutions found on forums to fix it, but nothing works.
Do you have any Idea for me?
Thank you
Raph
Fabien Tencé
Hi Raph,
I’m not sure but “\xeb” seems to be the “ë” character. Do you have a “ë” in your username? If so, it may be the cause of the problem. Install Anaconda in another directory and use the
base_compiledir
flag (see in the article or in the comments). Also make sure your user have read and write rights in the directory you installed Anaconda.Or, less subtle, create another account with ascii characters only.
Raph
Merci bcp!
Oui effectivement ça pourrait provenir de mon nom d’Utilisateur, je vais tester et je vous tiens au courant
Aa
Great tutorial, it just works! Is there a reason, why you didn’t use “conda install theano”? I followed your CUDA chapter, but then installed theano directly via conda, created the .theanorc file as you suggested and then imported theano for the first time in python and it worked perfectly. Finally, I followed the Keras chapter to get Keras up and running.
Fabien Tencé
Hi,
Yes, using Theano from GitHub give you access to the latest improvements (but also bugs), the same goes with Keras. If your installation is working fine and you don’t have any problem or speed issues, you can stick to
conda install theano
.Martin Novak
Hi Fabien!
I’m experiencing an error “ERROR (theano.sandbox.cuda): nvcc compiler not found on $PATH. Check your nvcc installation and try again.”
I understand what it says, but I’ve checked the $PATH several times, and it has correctly the “C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin” directory, so I don’t know why I get this error. My “.theanorc” is correct too.
I’ve checked with VS2013 if CUDA works, like you’ve suggested it in the tutorial, and it worked. How can I solve this?
Fabien Tencé
Hi Martin!
The nvcc compiler should be in
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\
. It should have been added to your system PATH by the CUDA installer. You should try to reinstall CUDA and check thatwhere nvcc
returnsC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.exe
. I don’t remember if the CUDA installer asks you if you want the PATH to be updated, but if it does, be sure to check that option.Martin Novak
This was the problem! I’ve added it to $PATH, and now it works like a charm!
Thank you!
Charles
Fabien great post!
I am having a problem getting theano to run off my GPU. Everything installs correctly and my PATH is updated for all the dependencies but it still only runs on my CPU.
My theanorc file specifies GPU and the CUDA software works when I run the test you suggested. The only other strange thing was I did not have to edit the __init__.py file, it did not have that if statement in it.
Any help is much appreciated!!
Charles
Please ignore my comment!
Also, despite what you read on the internet do not put a ‘.’ after the .theanorc file name!
Once again great post, I would have a very expensive useless GPU if it was not for this! Thank you.
Fabien Tencé
Hi Charles,
You’re right, I also saw some sources telling you to add a ‘.’ after the .theanorc file name but it doesn’t work!
You’re also right, the check for Python 3.5 was removed few days ago, I’ll update my article, thank you for the feedback.
Aravind
Thanks a lot for this concise tutorial!
Helped a lot.
Gabriel
I can’t imagine the number of hours that you saved windows users. Thank you. And thanks for the graphviz installation too, I spent way too much time on this before reading this tutorial.
Andrea
Hi,
Great tutorial, although I’m facing some problems. I want to run on a GTX1060 GPU
I could not run the CUDA 8.0 tutorials on VisualStudio2013:
C:\ProgramData\NVIDIA Corporation\CUDA Samples\v8.0\5_Simulations\oceanFFT\oceanFFT_vs2013.vcxproj(36,5): The imported project “C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\CUDA 8.0.props” was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
But it ran fine on visual studio 15
I could proceed until the testTheano.py. I cd in its folder and run “python testTheano.py” — it shows some errors:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\crtdefs.h(10): fatal error C1083: Cannot open include file: ‘corecrt.h’: No such file or directory
nvcc warning : The ‘compute_20’, ‘sm_20’, and ‘sm_21’ architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
mod.cu
WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not available (error: cuda unavailable)
Looping 1000 times took 15.088387 seconds
Result is [ 1.23178029 1.61879337 1.52278066 …, 2.20771813 2.29967761
1.62323284]
Used the cpu
So
– Should I fix the visualstudio 2013 problem? If so, how
– Can I stick with 2015? if so, how to make gpu work?
Andrea
NEVERMIND I SOLVED IT!
thanks for this
btw anaconda users can skip the mingw installation by doing:
conda install theano
Anastasios Tsiolakidis
How did you solve it? On my Windows 7 machine the instructions worked flawlessly and reestablished (a little bit) my faith in humanity. It has to be said I am not so sure about the cd %USERPROFILE%\Anaconda3\libs part. Anacondas installation gave me no such directories under USERPROFILE, so instead I used Anacondas install dir where everything was. On my windows 10 machine I already had VS2015 and Cuda, and discovered a whole bunch of libs and includes had to be correctly edited somewhere (there seems to have been some moving around of stuff since 2013), finally I copied a lot of stuff from the Windows SDK into Anaconda and it started working – don’t try this at home! Except, keras is giving me the weirdest behavior, I can import it when I start python shell, but something like “python keras.py” says keras not found. It is a “typical” Python problem and perhaps related that Anaconda is on a different drive from %USERPROFILE% , but still mysterious to me, since the theano test works.
jimmy wood
Hi
Thanks for the tutorial. I have completed all the steps, including trying various modifications suggested in the comments above relating to similar problems to mine, but I cannot get the theano test file to run. It produces the error below. Any suggestions would be most welcome, thanks
Problem occurred during compilation with the command line below:
C:\MinGw64\mingw64\bin\g++.exe -shared -g -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -DMS_WIN64 -I”C:\Users\Dell\Anaconda3\lib\site-packages\numpy\core\include” -I”C:\Users\Dell\Anaconda3\include” -I”C:\Users\Dell\Anaconda3\lib\site-packages\theano\theano\gof” -L”C:\Users\Dell\Anaconda3\libs” -L”C:\Users\Dell\Anaconda3″ -o c:\theano_compiledir\compiledir_Windows-10-10.0.14393-SP0-Intel64_Family_6_Model_94_Stepping_3_GenuineIntel-3.5.2-64\lazylinker_ext\lazylinker_ext.pyd c:\theano_compiledir\compiledir_Windows-10-10.0.14393-SP0-Intel64_Family_6_Model_94_Stepping_3_GenuineIntel-3.5.2-64\lazylinker_ext\mod.cpp -lpython35
The system cannot find the path specified.
Traceback (most recent call last):
File “C:\Users\Dell\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py”, line 75, in
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\Dell\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py”, line 92, in
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “theanotest.py”, line 1, in
from theano import function, config, shared, sandbox
File “C:\Users\Dell\Anaconda3\lib\site-packages\theano\theano\__init__.py”, line 66, in
from theano.compile import (
File “C:\Users\Dell\Anaconda3\lib\site-packages\theano\theano\compile\__init__.py”, line 10, in
from theano.compile.function_module import *
File “C:\Users\Dell\Anaconda3\lib\site-packages\theano\theano\compile\function_module.py”, line 21, in
import theano.compile.mode
File “C:\Users\Dell\Anaconda3\lib\site-packages\theano\theano\compile\mode.py”, line 10, in
import theano.gof.vm
File “C:\Users\Dell\Anaconda3\lib\site-packages\theano\theano\gof\vm.py”, line 659, in
from . import lazylinker_c
File “C:\Users\Dell\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py”, line 127, in
preargs=args)
File “C:\Users\Dell\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py”, line 2308, in compile_str
(status, compile_stderr.replace(‘\n’, ‘. ‘)))
. ception: Compilation failed (return status=1): The system cannot find the path specified.
Shi-Wan Lin
Thank you for sharing the installation steps – detailed and concise – it works for me both with or without GPU in Windows machines. You have saved me potentially many hours of trials and errors.
Fillan
Excellent guide! thank you so much for sharing your knowledge 🙂
Quick question, the NVCC cmd prompt window keeps popping up when i run the Keras code. Do you know how it can be suppressed to run in background?
Fabien Tencé
Hi Fillan,
I never saw any NVCC cmd prompt so I’m not of any help. Maybe someone has a solution…
Hong
Hi,Fabien
I have installed Keras according to your guide.
The guide is very nice!
My OS is window 10, I installed CUDA 8.0 and VisualStudio2013.
I installed a GTX 1070 card.
For the python , the version is 3.5.2.
When I run the testKeras.py, it report a issue that “python has stoped work”.
I debug into and find the below detail issue:
Unhandled exception at 0x00007FF93A918283 (ntdll.dll) in python.exe: 0xC0000374: 堆已损坏。 (parameters: 0x00007FF93A96F6B0).
But if I chang the nb_epoch from 20 to 10, there is no such issue.
Do you know the reason? Do I need to try the python 3.4?
Hong
Hong
I debug into the visual studio and find the call stack as below:
ntdll.dll!00007ffabbbb8283() Unknown
ntdll.dll!00007ffabbbb8bda() Unknown
ntdll.dll!00007ffabbb65b9a() Unknown
ntdll.dll!00007ffabbafc895() Unknown
> ucrtbase.dll!00007ffab8eee3bb() Unknown
python35.dll!tupledealloc(PyTupleObject * op) Line 235 C
python35.dll!code_dealloc(PyCodeObject * co) Line 366 C
python35.dll!tupledealloc(PyTupleObject * op) Line 235 C
python35.dll!code_dealloc(PyCodeObject * co) Line 366 C
python35.dll!func_dealloc(PyFunctionObject * op) Line 551 C
python35.dll!free_keys_object(_dictkeysobject * keys) Line 352 C
python35.dll!PyDict_Clear(_object * op) Line 1358 C
python35.dll!dict_tp_clear(_object * op) Line 2550 C
python35.dll!delete_garbage(_gc_head * collectable, _gc_head * old) Line 867 C
python35.dll!collect(int generation, __int64 * n_collected, __int64 * n_uncollectable, int nofail) Line 1019 C
python35.dll!PyImport_Cleanup() Line 481 C
python35.dll!Py_Finalize() Line 579 C
python35.dll!Py_Main(int argc, wchar_t * * argv) Line 804 C
[External Code]
The issue seem to be directly related with ucrtbase.dll.
When I search this file , and find severl different version:
C:\Windows.old\WINDOWS\SysWOW64
C:\Windows\System32
C:\Program Files\Anaconda3\Library\bin
How to know which version of this dll file is used by python 3.5? If I find the “C:\Windows\System32” one is used, how to correct it?
Anybody can help me?
Thanks
Hong
Julius
Hi, thanks for the tutorial! I’m not able to get CUDA to work with Visual Studio. When I try to build the ocean simulation as you suggested I get the following error:
Error 45 error : The CUDA Toolkit v8.0 directory ” does not exist. Please verify the CUDA Toolkit is installed properly or define the CudaToolkitDir property to resolve this error.
I checked on the CUDA installation guide for windows (https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/) and Table 2 says that Visual Studio Community 2015 DOES have support for CUDA 8.0 but it doesn’t list VS Community 2013. Has this changed since you wrote your instructions? I’m uninstall VSC 2013 update 5 and trying it with VSC 2015.
Fabien Tencé
Hi Julius,
CUDA and Visual Studio compatibilities evolves pretty fast so my tutorial may be deprecated on this point. It should however work with VS2013 so the error may have another cause.
Elle
Hi Fabien,
This is a great tutorial, Thank you! I managed to get Theano working fine, but am now stuck on getting Keras working.
I have un-installed and re-installed Keras but the same error persists:
raise JSONDecodeError(“Extra data”, s, end)
JSONDecodeError: Extra data
How can I find the cause of this error? I am so close and yet so far! :-/
Elle
SOLVED: The cause of the problem was some python comments in the top of the keras.py file that configures it to use Theano as the backend.
After deleting those surplus comments, the test import of keras worked just fine.
Talfan
Made fantastically straightforward, thanks!
Mike
Amazing Fabien, thank you very much, this is the best step by step installation post I have ever seen!
Anthony
Hi Fabien,
I dont know if you could help me.
Im stuck in the Cuda test step.
Whenever i make the instance, the Windows where i supossed the ocean should appear closes and brings me this
First-chance exception at 0x00007FFF503F7788 in oceanFFT.exe: Microsoft C++ exception: cufftResult_t at memory location 0x000000524FD1FBD8.
The thread 0x1424 has exited with code 1 (0x1).
The thread 0xb54 has exited with code 1 (0x1).
The thread 0x13f4 has exited with code 1 (0x1).
The program ‘[5896] oceanFFT.exe’ has exited with code 1 (0x1).
Thank you for your time and answer.
I dont know if everything is okay cuz it doesnt say crash anywhere but i didnt see any ocean neither. Than
AbdL
thank you very much for this step-by-step installation instructions!
I just had to add one extra line in the .theanorc file
to make it work
cxx = C:\mingw64\bin\g++.exe
Val Madrid
Awesome guide! Was able to do it step by step without a hitch. 🙂 This will help me greatly in my image processing modules for classification
Chris Patmore
Hi Fabien,
I seem to be having a problem others were seeing, but am unable to find a solution.
I have followed your steps exactly but the Theano test fails to run.
The error messages are as follows:
Problem occurred during compilation with the command line below:
“C:\Users\Chris\MinGWFiles\mingw64\bin\g++.exe” -shared -g -march=haswell -mmmx -mno-3dnow -msse -msse2 -msse3 -mssse3 -mno-sse4a -mcx16 -msahf -mmovbe -maes -mno-sha -mpclmul -mpopcnt -mabm -mno-lwp -mfma -mno-fma4 -mno-xop -mbmi -mbmi2 -mno-tbm -mavx -mavx2 -msse4.2 -msse4.1 -mlzcnt -mno-rtm -mno-hle -mrdrnd -mf16c -mfsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mxsave -mxsaveopt -mno-avx512f -mno-avx512er -mno-avx512cd -mno-avx512pf -mno-prefetchwt1 -mno-clflushopt -mno-xsavec -mno-xsaves -mno-avx512dq -mno-avx512bw -mno-avx512vl -mno-avx512ifma -mno-avx512vbmi -mno-clwb -mno-pcommit -mno-mwaitx –param l1-cache-size=32 –param l1-cache-line-size=64 –param l2-cache-size=6144 -mtune=haswell -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -DMS_WIN64 -I”C:\Users\Chris\Anaconda3\lib\site-packages\numpy\core\include” -I”C:\Users\Chris\Anaconda3\include” -I”C:\Users\Chris\Anaconda3\lib\site-packages\theano\theano\gof” -L”C:\Users\Chris\Anaconda3\libs” -L”C:\Users\Chris\Anaconda3″ -o C:\theano_compiledir\compiledir_Windows-10-10.0.14393-SP0-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-3.5.2-64\lazylinker_ext\lazylinker_ext.pyd C:\theano_compiledir\compiledir_Windows-10-10.0.14393-SP0-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-3.5.2-64\lazylinker_ext\mod.cpp -lpython35
Traceback (most recent call last):
File “C:\Users\Chris\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py”, line 75, in
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\Chris\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py”, line 92, in
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “testTheano.py”, line 1, in
from theano import function, config, shared, sandbox
File “C:\Users\Chris\Anaconda3\lib\site-packages\theano\theano\__init__.py”, line 66, in
from theano.compile import (
File “C:\Users\Chris\Anaconda3\lib\site-packages\theano\theano\compile\__init__.py”, line 10, in
from theano.compile.function_module import *
File “C:\Users\Chris\Anaconda3\lib\site-packages\theano\theano\compile\function_module.py”, line 21, in
import theano.compile.mode
File “C:\Users\Chris\Anaconda3\lib\site-packages\theano\theano\compile\mode.py”, line 10, in
import theano.gof.vm
File “C:\Users\Chris\Anaconda3\lib\site-packages\theano\theano\gof\vm.py”, line 663, in
from . import lazylinker_c
File “C:\Users\Chris\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py”, line 127, in
preargs=args)
File “C:\Users\Chris\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py”, line 2309, in compile_str
(status, compile_stderr.replace(‘\n’, ‘. ‘)))
all installations are found correctly when checked with where. I have also included base_compiledir=C:\theano_compiledir in the .theanorc file
Many Thanks
Chris Patmore
Just as FYI I have just fixed this by using conda install libpython from http://simranmetric.com/installing-theano-on-windows-10-python-3-5/ I have no idea why it works.
Fabien Tencé
Hi Chris,
Thanks for the feedback, it will be useful for other users!
Sky
Great tutorial – maybe this is obvious to other people but it might be good to add a note saying to make sure to install Anaconda only for the local user. I had problems using using the graphing libraries when I had it installed for the super user (am in the process of reinstalling now)
Fabien Tencé
Hi Sky,
You’re right, things are much simpler if you install only for the local user but it should work too if you install for all.
Lin
Fabien Tencé thanks for you instruction it really help me successfully install keras
Alister
I was wrestling to install Theano ,if you’re keep facing this problem “module ‘theano’ has no attribute ‘gof'” it means there is problem with your theano installation . all you need to do is downloadng theano zip file then extract it in the Anaconda3\Lib\site-packages folder and install it again . i hope it helps some of you !
Arun V
Hi Fabien,
I tried running the testKeras code and seems to giving me this error: FileNotFoundError: [WinError 3] The system cannot find the path specified: ‘C:/blaslapack’
The compiler pointed to error in model.fit line. I went through “where cl” command and it couldnt find the path nor could it find for nvcc but I added this for cl C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin and for nvcc I added the line
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
in theano file
I do have numpy and scipy installed and am using anaconda
Ali Abul Hawa
Hi Fabien,
Thanks for the detailed and clear installation instructions. I installed theano/keras/cuda… a few months ago, and it worked like a charm.
After formatting my disk, I re-installed everything today, and it also worked, however, theano’s new version (0.9.0beta1.dev), throws the following warning:
###############################
Using Theano backend.
WARNING (theano.sandbox.cuda): The cuda backend is deprecated and will be removed in the next release (v0.10). Please switch to the gpuarray backend. You can get more information about how to switch at this URL:
https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29
Using gpu device 0: GeForce GTX 960M (CNMeM is disabled, cuDNN not available)
###############################
It would be great if you can add the necessary modifications to your instructions that would use the gpuarray backend
Many thanks!
Yann
Thanks Fabien for the details!
I just want to let you know that it s works well with anaconda 4.3.0 (so python 3.6)
al
I love you
Raghu
Hi Fabien:
I am having some problems getting the gpu going (cpu works) with your fantastic directions.
I have followed with your checks as shown in the end of the message.
The cpu goes through but not the gpu though I have installed CUDA and an nvidia card. I get the error below:
ERROR (theano.gpuarray): pygpu was configured but could not be imported or is too old (version 0.6 or higher required)
NoneType: None
[Elemwise{exp,no_inplace}()]
Looping 1000 times took 12.478316 seconds
Result is [ 1.23178029 1.61879337 1.52278066 …, 2.20771813 2.29967761
1.62323284]
Used the cpu
[Finished in 16.6s]
Would appreciate your feedback.
Thank you and Regards.
Raghu
________________________________________________________________________________________
> where python
F:\Users\Raghu\Anaconda3\python.exe
> where gcc
f:\x86_64-5.4.0-release-posix-seh-rt_v5-rev0\mingw64\bin\gcc.exe
> where g++
f:\x86_64-5.4.0-release-posix-seh-rt_v5-rev0\mingw64\bin\g++.exe
> where gendef
f:\x86_64-5.4.0-release-posix-seh-rt_v5-rev0\mingw64\bin\gendef.exe
> where dlltool
f:\x86_64-5.4.0-release-posix-seh-rt_v5-rev0\mingw64\bin\dlltool.exe
> where cl
f:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe
> where nvcc
F:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.exe
Kai
Everything went well, but you have to use import keras at the beginning, he then creates or checks for your already created *.json file. you can also run import keras in notebook and then alter the created json file. this is considered for everyone who gets the keras.model not found (folowing it exactly like me). This could also be realted to me using Python 3.6 8it woirks fine jsut at the beginning isntead python35 use python36 all time. cheers and thx for the great work.
Hanan
Hi, thank you for your blogpost.
Tried to follow it yet I get:
File “C:\Users\\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py”, line 302, in dlimport
rval = __import__(module_name, {}, {}, [module_name])
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
i3v
It looks like some things changed since this article was written. I’ve used it to install theano and keras a while ago, and it perfectly worked. But today it looks a bit outdated.
I’ve just successfully installed theano 0.9.0 and keras 2.0.2 to an Anaconda virtual environment with python 3.6 on Windows 7 x64.
Differences:
* It’s OK to simply install theano 0.9.0 from anaconda. It just works. (It’s still a good idea to check if GPU is working OK with the script provided here)
* I ran into “Unknown MS Compiler version 1900” issue, when installing keras (described here: https://bugs.python.org/issue25251). This simple patch helps: https://bugs.python.org/file40608/patch.diff
Fabien Tencé
Hi,
Thanks for this feedback, it looks like I’ll have to update (again!) this article.
Tom
Hi Fabien, how do you add a directory “to the path”, as mentioned in the step 2) of “Installing CUDA”, and step 3) of “Installing Theano” ?
Thanks
Fabien Tencé
Hi Tom,
A bit late, but I cited this article in the comments on how to update your PATH.
Ivan
Hi Fabian,
Thanks for the article, I have used it to install all the libraries and it is working perfectly.
I have also installed Tensorflow with gpu very easily using pip install tensorflow-gpu and cuDNN, and I wrote an article to explain it in detail:
https://sites.google.com/site/ivanhuertacasado/installing-keras-theano-tensorflow-with-gpu-windows/
Ivan
Sam Ranade
Hello all,
I have windows 10, python3.5, 4GB grphics card. I had downloaded the CUDA network installer. I stopped the install when it said it would overwrite the existing display driver. This shwn I panicked and stopped the install.
@Fabien and others
Have you experienced the same dire warning of display drivers being overwritten and still gone ahead?
Can I safely assume that I will in fact see folders like C:\ProgramData\NVIDIA Corporation\CUDA Samples\v8.0 and in that a file Samples_vs2013.sln?
I am acomplete techno-Nancy so relying on you all as support network.
Thanks in advance.
Fabien Tencé
Hi Sam,
I had the same warning about the installer overwriting the current display driver and you can continue the install. It only downgrades your current display driver to an older version. Everything should work fine after the downgrade but you can (and should) reinstall the latest drivers you can find on http://www.nvidia.com/download/index.aspx. After this operation, you should have both CUDA and the latest drivers for your card.
You should be able to follow the rest of the tutorial from here.
Aris
I followed the instructions and I get this error :
ValueError: Invalid value (“cpu”) for configuration variable “gpu”. Valid options start with one of “device”, “opencl”, “cuda”
Aris
Traceback (most recent call last):
File “”, line 1, in
import theano
File “C:\Users\user\Anaconda3\lib\site-packages\theano\theano\__init__.py”, line 67, in
from theano.configdefaults import config
File “C:\Users\user\Anaconda3\lib\site-packages\theano\theano\configdefaults.py”, line 113, in
in_c_key=False)
File “C:\Users\user\Anaconda3\lib\site-packages\theano\theano\configparser.py”, line 285, in AddConfigVar
configparam.__get__(root, type(root), delete_key=True)
File “C:\Users\user\Anaconda3\lib\site-packages\theano\theano\configparser.py”, line 333, in __get__
self.__set__(cls, val_str)
File “C:\Users\user\Anaconda3\lib\site-packages\theano\theano\configparser.py”, line 344, in __set__
self.val = self.filter(val)
File “C:\Users\user\Anaconda3\lib\site-packages\theano\theano\configdefaults.py”, line 100, in filter
% (self.default, val, self.fullname)))
ValueError: Invalid value (“cpu”) for configuration variable “gpu”. Valid options start with one of “device”, “opencl”, “cuda”
Ariel
I have the same problem!
How can we fix it??
Mina
Dear Fabien Tence,
I did everything according to this tutorial step by step , but when I want to run testKeras.py, I encounter “No module named ‘tensorflow’ “. I also changed backend to “theano” and image_dim_ordering to “th” but it does not work.
I would be grateful if you help me with this problem.
Nader
Can you please update the step by step installation.
Thank you
Nader
Please note that according to the following link and theano, we should not install mingw …. please let me know if I understand this correctly.
https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end(gpuarray)
Robert Schnabel
well I’ve spent 2 solid days trying to install Keras, Theano, TensorFlow for Python on Windows 10.
Total FAILURE for mysterious version/dependency reasons.
I’m not the world’s greatest computer engineer but I’d really like to study these packages.
It’s truly discouraging how HARD it is to install them. Surely there’s gotta be an easier way.
You are aware there are DOZENs of ‘sure-fire’ INSTALL instructions out there…each one different and NONE of em work (for me at least)….
Thanks anyway…..
Benny
thanks a lot!!! I can finally use Keras with theano 🙂
LuigiX
I have noticed that your blog needs some fresh content.
Writing manually takes a lot of time, but there is tool
for this boring task, search for: unlimited content Wrastain’s tools
Pranav
Hi Fabien
I’m having a bit of a problem. I followed all the steps till installation of theano, and when I try to run the test theano file I’m getting this error:
Can not use cuDNN on context None: cannot compile with cuDNN. We got this error:
b’C:\\Users\\prana\\AppData\\Local\\Temp\\try_flags_ncc2e93w.c:4:19: fatal error: cudnn.h: No such file or directory\r\ncompilation terminated.\r\n’
Mapped name None to device cuda: GeForce GTX 1050 Ti (0000:01:00.0)
Please help. Thanks
Thomas
Thanks, this guide helped me get the missing pieces in place. You’re a life saver!
Ary
Hello.
When I try to execute the command ” gendef ..\python35.dll “, I get an error message saying This app can’t run on your PC. To find a version for your PC, contact the software publisher. And there’s “Access is denied” in the command prompt. Any help ?
Dor
Hi,
Great tutorial 🙂
small question:
1. I didn’t install Conda (using CPU) – How can I operate step 5 in Keras :
conda install graphviz
pip install git+https://github.com/nlhepler/pydot.git
Fabien Tencé
Hi Dor,
This step is optional, you only have to install that if you want to draw graphs representing the different layers of your networks.
If it is what you want, you should be able to install graphviz with the command
pip install graphviz
(with admin rights or not, depending on your installation).Nikiforos
Hello, I followed your steps but when i try to execute the theano code i get the following error, did not find any solution online..
Traceback (most recent call last):
File “file.py”, line 1, in
import theano.tensor as T
File “C:\Users\310297685\Anaconda3_4.2.0\lib\site-packages\theano\theano\__init__.py”, line 68, in
from theano.version import version as __version__
File “C:\Users\310297685\Anaconda3_4.2.0\lib\site-packages\theano\theano\version.py”, line 14, in
int(short_version.split(‘.’)[2])
IndexError: list index out of range
Any ideas to fix it? Thanks a lot.
Nikiforos
Fixed my problem! I had many Theno’s installed. I had to execute ‘conda uninstall theano’ multiple times till no Theano is present. Then I installed again and no problem.
Fabien Tencé
Hi Nikiforos,
Thanks for giving the solution, it might help someone having the same problem.
Alex G
Great set of instructions but for some reason I can’t quite cross the finish-line with cuDNN. I’ve through the trouble of doing a clean install of Anaconda3 (v5.0) and creating a separate environment with python 3.5 with Theano Tensorflow and Keras installed. If I run with the cnDNN flag as False, no errors or issues. If I set it to True, I get this-
ERROR (theano.gpuarray): Could not initialize pygpu, support disabled
Traceback (most recent call last):
File “C:\Users\Sasha\Anaconda3\envs\py35\lib\site-packages\theano\gpuarray\__init__.py”, line 164, in
use(config.device)
File “C:\Users\Sasha\Anaconda3\envs\py35\lib\site-packages\theano\gpuarray\__init__.py”, line 151, in use
init_dev(device)
File “C:\Users\Sasha\Anaconda3\envs\py35\lib\site-packages\theano\gpuarray\__init__.py”, line 66, in init_dev
avail = dnn.dnn_available(name)
File “C:\Users\Sasha\Anaconda3\envs\py35\lib\site-packages\theano\gpuarray\dnn.py”, line 174, in dnn_available
if not dnn_present():
File “C:\Users\Sasha\Anaconda3\envs\py35\lib\site-packages\theano\gpuarray\dnn.py”, line 165, in dnn_present
dnn_present.msg)
RuntimeError: You enabled cuDNN, but we aren’t able to use it: cannot compile with cuDNN. We got this error:
b’C:\\Users\\Sasha\\AppData\\Local\\Temp\\try_flags_u4afi317.c:4:19: fatal error: cudnn.h: No such file or directory\r\ncompilation terminated.\r\n’
This is my .theanorc-
[global]
floatX = float32
device = gpu
base_compiledir=c:\theano_compiledir
[nvcc]
flags=-L”C:\Users\Sasha\Anaconda3″
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
[lib]
cnmem = 0.8
[blas]
ldflags=-LC:\openblas -lopenblas
[dnn]
enabled = True
Fabien Tencé
Hi Alex,
It seems you use the new Theano GPU backend (gpuarray), and I don’t know much on this, sorry. Maybe a clean install using these instructions could help you.
ale b
Hello thx for the tutorial. would this work with cuda 9?
Fabien Tencé
Hi,
I didn’t test this setup, so I can’t be sure. It should work, however you should be careful with the version of Visual Studio you’re using, as there are still compatibility issues between CUDA and VS 2017 (see this post on SO).
Be sure to check for CUDA/CuDNN compatibility too, see on the download page.
Ebrahimi
Hi.
I would greatly appreciate if you could let me know how to fix this error:
C:\Users\Markazi.co\Anaconda3\python.exe D:/mifs-master_2/MU/learning-from-imbalanced-classes-master/learning-from-imbalanced-classes-master/continuous/logit-plot1.py
You can find the C code in this temporary file: C:\Users\Markazi.co\AppData\Local\Temp\theano_compilation_error__q6g2bid
Traceback (most recent call last):
File “C:\Users\Markazi.co\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py”, line 75, in
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\Markazi.co\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py”, line 92, in
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “D:/mifs-master_2/MU/learning-from-imbalanced-classes-master/learning-from-imbalanced-classes-master/continuous/logit-plot1.py”, line 1, in
import theano.tensor as T
File “C:\Users\Markazi.co\Anaconda3\lib\site-packages\theano\__init__.py”, line 110, in
from theano.compile import (
File “C:\Users\Markazi.co\Anaconda3\lib\site-packages\theano\compile\__init__.py”, line 12, in
from theano.compile.mode import *
File “C:\Users\Markazi.co\Anaconda3\lib\site-packages\theano\compile\mode.py”, line 11, in
import theano.gof.vm
File “C:\Users\Markazi.co\Anaconda3\lib\site-packages\theano\gof\vm.py”, line 673, in
from . import lazylinker_c
File “C:\Users\Markazi.co\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py”, line 127, in
preargs=args)
File “C:\Users\Markazi.co\Anaconda3\lib\site-packages\theano\gof\cmodule.py”, line 2359, in compile_str
(status, compile_stderr.replace(‘\n’, ‘. ‘)))
.
Process finished with exit code 1