Goal
Use Python-trained (keras) model in c/c++.
See section work-around for c-work-around.
Compile Tensorflow from source (rev 1.0 or 1.2.1)
following the instructions from
https://www.tensorflow.org/install/install_windows
(tensorflow already is installed via pip in python3, but I need to use it from c++, so installing from source seems mandatory)
System
win7(64)
bazel 0.5.2,
python(env) 3.5.2 (64),
pip(env) 9.0.1,
msys64/msys2_shell.cmd (GNU bash, 4.4.12 (64-pc-msys))
gcc 6.3.0
java SE "1.8.0_131",
CUDA 8.0.60 (not used).
Error
(full logs are below in extra sections)
in msys2-shell, setting environment vars, activate python virt-env, doing bazel clean, ./configure,
bazel build --verbose_failures --config=opt //tensorflow/tools/pip_package:build_pip_package
I get this error:
ERROR: D:/user/sourcen/external/tensorflow-master-201707051514/
tensorflow-master-rev-1-2-1/tensorflow/core/BUILD:1415:1:
Executing genrule //tensorflow/core:version_info_gen failed:
bash.exe failed: error executing command
cd C:/users/user/appdata/local/temp/_bazel_user/chogfwdz/execroot/org_tensorflow
C:/tools/msys64/usr/bin/bash.exe
-c source external/bazel_tools/tools/genrule/genrule-setup.sh;
tensorflow/tools/git/gen_git_source.py
--generate tensorflow/tools/git/gen/spec.json
tensorflow/tools/git/gen/head
tensorflow/tools/git/gen/branch_ref
"bazel-out/host/genfiles/tensorflow/core/util/version_info.cc":
com.google.devtools.build.lib.shell.
BadExitStatusException: Process exited with status 3.
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
Sorry, I am absolutely lost here, this message tells me nothing.
Here some snippets from the files mentioned above, maybe somebody has a glue and gives me a hint for enlightment....
//tensorflow/core/BUILD:1415:1
tf_version_info_genrule()
cc_library(
name = "version_lib",
srcs = ["util/version_info.cc"],
hdrs = ["public/version.h"],
copts = tf_copts(),
)
bazel/.../genrule-setup.sh
set -e
set -u
set -o pipefail
//tensorflow/tools/git/gen_git_source.py
"""... creates symlinks from the internal git repository directory so
that the build system can see changes in the version state. ..."""
def parse_branch_ref(filename)...
def configure(src_base_path, debug=False)...
def get_git_version(git_base_path)...
def write_version_info(filename, git_version)...
def generate(arglist)...
def raw_generate(output_file)...
I suppose, that the wrong python version is used (not the virtualenv I activated) - there are several other python versions (2.7-32, 2.7-64, 3.5-32, 3.5-64) installed (which are needed otherwise).
Questions
What can I do to check, if bazel is using the right python (virtualenv)?
If bazel is using the wrong one, how can I change this?
If bazel is using the right version, how can I get more details about what is going wrong (and fix it)?
Meta-Questions
What further information are needed (environment variables)?
What can I do to improve the question to enable people to give advices?
(please give comments, what is missing, wrong, unclear, too much)
Next steps
I searched for "Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'"
tried to do the procedure below with a local admin account -> blocked by the company firewall
tried to set PYTHONPATH and PYTHONHOME, no effect.
export PYTHONHOME=/D/bin/Python64-3-Anaconda/envs/python64-35
export PYTHONPATH=/D/bin/Python64-3-Anaconda/envs/python64-35:
/D/bin/Python64-3-Anaconda/envs/python64-35/lib/site-packages:
/d/bin/Python64-3-Anaconda/envs/python64-35/libs
try to set up another virtualenv (as admin)
try to install tensorflow via cmake
Procedure
This is what I did after starting msys2:
In TF 1.0, I did a work-around for the first problem I faced (download failure of numeric_min_js).
After some IRC talk & lots of tries - finally I commented out one line in
/tensorflow-rev1-0/tensorflow/tensorboard/bower/BUILD (see below).
So now ./configure script (TF 1.0) runs without errors (warnings about http_proxy can be ignored, as I 've been told on IRC and on some URLs I googled). Below I added full logs of the full build-attempt.
My Python virtual-env is in
d:/bin/Python64-3-Anaconda/envs/python64-35/python.exe,
As library-path I used:
D:/bin/Python64-3-Anaconda/envs/python64-35/lib/site-packages.
TF 1.0 attempt
patching BUILD (TF1.0)
.../tensorflow-rev1-0/tensorflow/tensorboard/bower/BUILD
filegroup(
name = "bower",
srcs = [
...
# "#numericjs_numeric_min_js//file", # by rg20170710
...
user#CRPC0815 MSYS ~
$ cd /d/user/Sourcen/external/tensorflow-rev1-0/
step 0: set env, activate python-env, cd
start msys2-shell:
$ c:/tools/msys64/msys2_shell.cmd
set the environment variables
user#CRPC0815 MSYS ~
$ source d:/user/00-Projekte/VrVis/env-cuda-python64-3--1.sh
activate virtual-env
$ cd /d/bin/Python64-3-Anaconda/
$ source activate python64-35
goto sources
$ cd /d/user/Sourcen/external/tensorflow-rev1-0
(python64-35)
user#CRPC0815 MSYS /d/user/Sourcen/external/tensorflow-rev1-0
$
step 1: bazel clean
(python64-35)
user#CRPC0815 MSYS /d/user/Sourcen/external/tensorflow-rev1-0
$ bazel clean
WARNING: ignoring http_proxy in environment.
....................
INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes.
step 2: ./configure
(python64-35)
user#CRPC0815 MSYS /d/user/Sourcen/external/tensorflow-rev1-0
$ ./configure
Please specify the location of python.
[Default is /D/bin/Python64-3-Anaconda/envs/python64-35/python]:
Please specify optimization flags to use during compilation [Default is -march=native]:
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N]
No XLA support will be enabled for TensorFlow
Found possible Python library paths:
D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages
D:\bin\Python64-3-Anaconda\envs\python64-35
Please input the desired Python library path to use.
Default is [D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages]
Using python library path: D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages
Junction created for util\python\python_include <<===>> D:\bin\Python64-3-Anaconda\envs\python64-35\include
Junction created for util\python\python_lib <<===>> D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages
Junction created for third_party\py\numpy\numpy_include <<===>> D:\bin\Python64-3-Anaconda\envs\
python64-35\lib\site-packages\numpy\core\include
Do you wish to build TensorFlow with CUDA support? [y/N]
No CUDA support will be enabled for TensorFlow
Configuration finished
WARNING: ignoring http_proxy in environment.
INFO: All external dependencies fetched successfully.
step 3: bazel build & error
$ bazel build --verbose_failures --config=opt //tensorflow/tools/pip_package:build_pip_package
WARNING: ignoring http_proxy in environment.
INFO: Found 1 target...
ERROR: D:/user/sourcen/external/tensorflow-rev1-0/tensorflow/core/BUILD:1227:1:
Executing genrule //tensorflow/core:version_info_gen failed:
bash.exe failed:
error executing command
cd C:/users/user/appdata/local/temp/_bazel_user/hnxszhzu/execroot/org_tensorflow
SET PATH=C:\tools\msys64\usr\bin;C:\tools\msys64\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35;
D:\bin\Python64-3-Anaconda\envs\python64-35\Library\mingw-w64\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35\Library\usr\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35\Library\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35\Scripts;
C:\tools\msys64\usr\bin;
D:\user\bin\BLAS;
D:\bin\TDM-GCC-64\bin;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\bp2qlotc.p22\NativeBinaries\x86;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\;
C:\Program Files (x86)\MSBuild\14.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\libnvvp;
C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\lib;
C:\Program Files\TortoiseGit\bin;
C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;
C:\ProgramData\Oracle\Java\javapath;
C:\Qt\Qt5.7.0\5.7\msvc2015;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\WINDOWS\system32;
D:\user\bin\MinGW\msys\1.0\bin;
D:\user\bin\MinGW\msys\1.0\sbin;
D:\user\bin\MinGW\msys\1.0\sbin\awk;
D:\bin\CMake\bin;
D:\bin\Git\bin;
[...]
D:\bin\Python64-3-Anaconda\envs\python64-35\DLLs;
D:\bin\Python64-3-Anaconda\envs\python64-35\Lib;
D:\bin\Python64-3-Anaconda\envs\python64-35\libs;
D:\bin\Slik-Subversion-1-9-2\bin;
D:\bin\SubversionColabnet\bin;
D:\bin\TDM-GCC-64\bin;
C:\tools\msys64\usr\local\bin;
C:\tools\msys64\usr\bin;
C:\tools\msys64\usr\bin;
C:\tools\msys64\opt\bin;
C:\Windows\System32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\tools\msys64\usr\bin\site_perl;
C:\tools\msys64\usr\bin\vendor_perl;
C:\tools\msys64\usr\bin\core_perl
C:/tools/msys64/usr/bin/bash.exe -c source external/bazel_tools/tools/genrule/genrule-setup.sh;
tensorflow/tools/git/gen_git_source.py
--generate tensorflow/tools/git/gen/spec.json
tensorflow/tools/git/gen/head
tensorflow/tools/git/gen/branch_ref
"bazel-out/host/genfiles/tensorflow/core/util/version_info.cc":
com.google.devtools.build.lib.
shell.BadExitStatusException: Process exited with status 3.
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
Current thread 0x0000628c (most recent call first):
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 5,500s, Critical Path: 0,41s
TF 1.2.1 build attempt
step 0: set env, activate python-env, cd
(the same as in TF 1.0)
$ source d:/user/00-Projekte/VrVis/env-cuda-python64-3--1.sh
$ cd /d/bin/Python64-3-Anaconda/
$ source activate python64-35
$ cd /d/user/Sourcen/external/tensorflow-master-201707051514/tensorflow-master-rev-1-2-1/
step 1: bazel clean
$ bazel clean
WARNING: ignoring http_proxy in environment.
INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes
step 2: ./configure
$ ./configure
WARNING: ignoring http_proxy in environment.
You have bazel 0.5.2- installed.
Please specify the location of python.
[Default is /D/bin/Python64-3-Anaconda/envs/python64-35/python]:
Found possible Python library paths:
D:\bin\Python64-3-Anaconda\envs\python64-35
D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages
Please input the desired Python library path to use.
Default is [D:\bin\Python64-3-Anaconda\envs\python64-35]
D:/bin/Python64-3-Anaconda/envs/python64-35/lib/site-packages
Do you wish to build TensorFlow with MKL support? [y/N]
No MKL support will be enabled for TensorFlow
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified
[Default is -march=native]:
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N]
No XLA support will be enabled for TensorFlow
Do you wish to build TensorFlow with VERBS support? [y/N]
No VERBS support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N]
No CUDA support will be enabled for TensorFlow
Do you wish to build TensorFlow with MPI support? [y/N]
MPI support will not be enabled for TensorFlow
Configuration finished
step 3: bazel build & error
(python64-35)
user#CRPC0815 MSYS /d/user/Sourcen/external/tensorflow-master-201707051514/tensorflow-master-rev-1-2-1
$ bazel build --verbose_failures --config=opt //tensorflow/tools/pip_package:build_pip_package
WARNING: ignoring http_proxy in environment.
INFO: Found 1 target...
ERROR: D:/user/sourcen/external/tensorflow-master-201707051514/tensorflow-master-rev-1-2-1/tensorflow/core/BUILD:1415:1:
Executing genrule //tensorflow/core:version_info_gen failed:
bash.exe failed:
error executing command
cd C:/users/user/appdata/local/temp/_bazel_user/chogfwdz/execroot/org_tensorflow
SET PATH=C:\tools\msys64\usr\bin;
C:\tools\msys64\bin;
C:\tools\msys64\usr\bin;
D:\user\bin\BLAS;
D:\bin\TDM-GCC-64\bin;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\bp2qlotc.p22\NativeBinaries\x86;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\;
C:\Program Files (x86)\MSBuild\14.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\libnvvp;
C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\lib;
C:\Program Files\TortoiseGit\bin;
C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;
C:\ProgramData\Oracle\Java\javapath;
C:\Qt\Qt5.7.0\5.7\msvc2015;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\WINDOWS\system32;
D:\BaslerPylon5\Runtime\Win32\;
D:\BaslerPylon5\Runtime\x64\;
D:\user\bin\MinGW\msys\1.0\bin;
D:\user\bin\MinGW\msys\1.0\sbin;
D:\user\bin\MinGW\msys\1.0\sbin\awk;
D:\bin\CMake\bin;
D:\bin\Git\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35;
D:\bin\Python64-3-Anaconda\envs\python64-35\Library\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35\Scripts;
D:\bin\Python64-3-Anaconda\envs\python64-35\DLLs;
D:\bin\Python64-3-Anaconda\envs\python64-35\Lib;
D:\bin\Python64-3-Anaconda\envs\python64-35\libs;
D:\bin\Slik-Subversion-1-9-2\bin;
D:\bin\SubversionColabnet\bin;
D:\bin\TDM-GCC-64\bin;
D:\bin\gnuplot\bin;
D:\user\bin;
.
C:/tools/msys64/usr/bin/bash.exe -c source external/bazel_tools/tools/genrule/genrule-setup.sh;
tensorflow/tools/git/gen_git_source.py
--generate tensorflow/tools/git/gen/spec.json
tensorflow/tools/git/gen/head tensorflow/tools/git/gen/branch_ref
"bazel-out/host/genfiles/tensorflow/core/util/version_info.cc":
com.google.devtools.build.lib.shell.
BadExitStatusException: Process exited with status 3.
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
Current thread 0x000036e8 (most recent call first):
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 5,413s, Critical Path: 0,52s
Work-Around
Meanwhile I found a work-around for deploying Tensorflow (Keras) Models (win7/win10) without need of bazel/cmake/sources....:
use the C-API c_api.h from win/cpu, c-api example
create lib from dll via vs2015 command prompt:
dumpbin /exports xxx.dll > xxx.def
pywrap_tensorflow_internal.lib
extract gpu lib from Python pywrap_tensorflow_internal.lib
copy pyd lib _pywrap_tensorflow_internal.pyd to dll-path
maybe use gpu-options (python -> c):
python code
gpu_options = tensorflow.GPUOptions(allow_growth=True)
config = tensorflow.ConfigProto(gpu_options=gpu_options)
serialized = config.SerializeToString()
[int(i) for i in serialized]
c-code for gpu-options:
TF_SessionOptions* sess_opts = TF_NewSessionOptions();
// tensorflow.GPUOptions(allow_growth=True) ...
uint8_t configProtoGPU[] = { 50, 2, 32, 1};
size_t configProtoGPUlen = sizeof(configProtoGPU) / sizeof(uint8_t);
TF_SetConfig(sess_opts, configProtoGPU, configProtoGPUlen, status);
When I try to import Theano in Python 2.7, I get the following error message:
'C:Program' is not recognized as an internal or external command,
operable program or batch file.
ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: ('nvcc return status', 1, 'for cmd', 'nvcc -shared -O3 -LC:\\Anaconda\\libs -use_fast_math -LC:\\Anaconda\\libs --compiler-bindir C:Program Files (x86)Microsoft Visual Studio 12.0VCbinamd64 -Xlinker /DEBUG -D HAVE_ROUND -m64 -Xcompiler -DCUDA_NDARRAY_CUH=18715462c72ed6afcd7ca5d52813ce90,-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION,/Zi,/MD -IC:\\Anaconda\\lib\\site-packages\\theano\\sandbox\\cuda -IC:\\Anaconda\\lib\\site-packages\\numpy\\core\\include -IC:\\Anaconda\\include -IC:\\Anaconda\\lib\\site-packages\\theano\\gof -o C:\\Users\\JACOB #1\\AppData\\Local\\Theano\\compiledir_Windows-10-10.0.10240-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.11-64\\cuda_ndarray\\cuda_ndarray.pyd mod.cu -LC:\\Anaconda\\libs -LC:\\Anaconda -lpython27 -lcublas -lcudart
I noticed that in the --compiler-bindir section, the path has no slashes (C:Program Files (x86)Microsoft Visual Studio 12.0VCbinamd64). I have checked my PATH, THEANO_FLAGS, and .theanorc.txt file and none have this path without the slashes. Is there a way to resolve this?
When I try to paste this command, inserting the slashes, into the command prompt, I get the following results:
nvcc fatal : Cannot find compiler 'cl.exe' in PATH
This makes no sense to me, as the first entry in my PATH is:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64
My .theanorc.txt is as follows:
[global]
device = gpu
floatX = float32
[cuda]
root = -LJ:\NVIDIA GPU Computing Toolkit\CUDA\v7.0
[nvcc]
flags = -LC:\Anaconda\libs
fastmath = True
compiler-bindir = -LC:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64
Any help would be greatly appreciated!
I could solve this problem by setting windows environment variable, instead of directly mentioning the path in compiler-bindir.
You can set windows environment variable by right click on
"start->computer->properties->advanced system settings"
Just check if cl.exe actually exists in the directory:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64
If it doesn't, then install it(along with all the other MS runtime files for C++, which doesn't come by default) by running the VS setup, select Modify option, then expand and select:
Programming Language -> C++
and install.
Hopefully, now it might work. Please be patient as that download might take quite a while...
PS: Iff possible, migrate your Theano workbase to UNIX based OS like (Ubuntu/Kali Linux/Manjaro) + Anaconda for SciPy and NumPy, as it poses much less of a problem than in Windows
I am having a LOT of trouble to start with these are my specs
windows 8
64 bit
python 2.7
Apachehaus 2.4.12
I cannot for the life of me figure out how to compile mod_wsgi to make the necessary mod_wsgi.so file from the source code.
https://github.com/GrahamDumpleton/mod_wsgi/releases
I'm trying to compile the ap24py27-win64-VC9.mk and after opening Visual C++ 2008 64-bit command prompt
c:\mod_wsgi-4.4.13> nmake -f ap24py27-win64-VC9.mk
c:\mod_wsgi-4.4.13\src\server\wsgi_python.h(24) : fatal error 1083: Cannot open include file: 'Python.h': No such file or directory wsgi_restrict.c
c:\mod_wsgi-4.4.13\src\server\wsgi_python.h(24) : fatal error 1083: Cannot open include file: 'Python.h': No such file or directory wsgi_server.c
c:\python27\mod_wsgi-4.4.13\src\server\wsgi_python.h(24) : fatal error C1083: Cannot open include file: 'Python.h': No such file or directory wsgi_stream.c
c:\mod_wsgi-4.4.13\src\server\wsgi_python.h(24) : fatal error C1083: Cannot open include file: 'Python.h': No such file or directory wsgi_validate.c
c:\mod_wsgi-4.4.13\src\server\wsgi_python.h(24) : fatal error C1083: Cannot open include file: 'Python.h': No such file or directory
Generating Code...
c:\mod_wsgi-4.4.13\src\server\wsgi_memory.c(124) : warning C4711: function 'getPeakRSS' selected for automatic inline expansion
c:\mod_wsgi-4.4.13\src\server\wsgi_memory.c(125) : warning C4711: function 'getCurrentRSS' selected for automatic inline expansion
NMAKE : fatal error U1077: '"C:\Users\User\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.EXE"' : return code '0x2'
Stop.
I already set my path to path=%path% Python27/include because that's where the Python.h file is.
I've also tried
python setup install
Traceback (most recent call last):
File "setup.py", line 139, in <module>
'missing Apache httpd server packages.' % APXS)
RuntimeError: The 'apxs' command appears not to be installed or is not executable. Please check the list of prerequisites in the documentation for this package and install any missing Apache httpd server packages.
The compiler doesn't use the PATH environment variable for finding header files. Usually it uses INCLUDE.
I think you can pass this into nmake, like so
nmake INCLUDE=pathToPythonHeader -f ap24py27-win64-VC9.mk
Why are you trying to compile it from source code? Why aren't you using the precompiled binaries?
There is nothing additional in the latter release that you would really need on Windows, so just grab and use the latest binary version which at this time is 4.4.12.
You also can't do a 'python setup.py install' nor a 'pip install' on Windows.
If you really do for some unknown reason need to build from source code, you do at least need to modify the ap24py27-win64-VC9.mk file and override the locations for where Python and Apache is installed. The default locations are based on a non standard layout that allows me to have many different Python and Apache versions installed for different architectures at the same time.
I understand that the Theano support for Windows 8.1 is at experimental stage only but I wonder if anyone had any luck with resolving my issues. Depending on my config, I get three distinct types of errors. I assume that the resolution of any of my errors would solve my problem.
I have installed Python using WinPython 32-bit system, using MinGW as described here. The contents of my .theanorc file are as follows:
[global]
openmp=False
device = gpu
[nvcc]
flags=-LC:\TheanoPython\python-2.7.6\libs
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\
[blas]
ldflags =
When I run import theano the error is as follows:
nvcc fatal : nvcc cannot find a supported version of Microsoft Visual Studio.
Only the versions 2010, 2012, and 2013 are supported
['nvcc', '-shared', '-g', '-O3', '--compiler-bindir', 'C:\\Program Files (x86)\\
Microsoft Visual Studio 10.0\\VC\\bin# flags=-m32 # we have this hard coded for
now', '-Xlinker', '/DEBUG', '-m32', '-Xcompiler', '-DCUDA_NDARRAY_CUH=d67f7c8a21
306c67152a70a88a837011,/Zi,/MD', '-IC:\\TheanoPython\\python-2.7.6\\lib\\site-pa
ckages\\theano\\sandbox\\cuda', '-IC:\\TheanoPython\\python-2.7.6\\lib\\site-pac
kages\\numpy\\core\\include', '-IC:\\TheanoPython\\python-2.7.6\\include', '-o',
'C:\\Users\\Matej\\AppData\\Local\\Theano\\compiledir_Windows-8-6.2.9200-Intel6
4_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.6-32\\cuda_ndarray\\cuda_ndarray
.pyd', 'mod.cu', '-LC:\\TheanoPython\\python-2.7.6\\libs', '-LNone\\lib', '-LNon
e\\lib64', '-LC:\\TheanoPython\\python-2.7.6', '-lpython27', '-lcublas', '-lcuda
rt']
ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: ('nvcc return st
atus', 1, 'for cmd', 'nvcc -shared -g -O3 --compiler-bindir C:\\Program Files (x
86)\\Microsoft Visual Studio 10.0\\VC\\bin# flags=-m32 # we have this hard coded
for now -Xlinker /DEBUG -m32 -Xcompiler -DCUDA_NDARRAY_CUH=d67f7c8a21306c67152a
70a88a837011,/Zi,/MD -IC:\\TheanoPython\\python-2.7.6\\lib\\site-packages\\thean
o\\sandbox\\cuda -IC:\\TheanoPython\\python-2.7.6\\lib\\site-packages\\numpy\\co
re\\include -IC:\\TheanoPython\\python-2.7.6\\include -o C:\\Users\\Matej\\AppDa
ta\\Local\\Theano\\compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepp
ing_3_GenuineIntel-2.7.6-32\\cuda_ndarray\\cuda_ndarray.pyd mod.cu -LC:\\TheanoP
ython\\python-2.7.6\\libs -LNone\\lib -LNone\\lib64 -LC:\\TheanoPython\\python-2
.7.6 -lpython27 -lcublas -lcudart')
WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not availabl
e
I have also tested it using Visual Studio 12.0 which is installed on my system with the following error:
mod.cu
nvlink fatal : Could not open input file 'C:/Users/Matej/AppData/Local/Temp/tm
pxft_00001b70_00000000-28_mod.obj'
['nvcc', '-shared', '-g', '-O3', '--compiler-bindir', 'C:\\Program Files (x86)\\
Microsoft Visual Studio 12.0\\VC\\bin\\', '-Xlinker', '/DEBUG', '-m32', '-Xcompi
ler', '-LC:\\TheanoPython\\python-2.7.6\\libs,-DCUDA_NDARRAY_CUH=d67f7c8a21306c6
7152a70a88a837011,/Zi,/MD', '-IC:\\TheanoPython\\python-2.7.6\\lib\\site-package
s\\theano\\sandbox\\cuda', '-IC:\\TheanoPython\\python-2.7.6\\lib\\site-packages
\\numpy\\core\\include', '-IC:\\TheanoPython\\python-2.7.6\\include', '-o', 'C:\
\Users\\Matej\\AppData\\Local\\Theano\\compiledir_Windows-8-6.2.9200-Intel64_Fam
ily_6_Model_60_Stepping_3_GenuineIntel-2.7.6-32\\cuda_ndarray\\cuda_ndarray.pyd'
, 'mod.cu', '-LC:\\TheanoPython\\python-2.7.6\\libs', '-LNone\\lib', '-LNone\\li
b64', '-LC:\\TheanoPython\\python-2.7.6', '-lpython27', '-lcublas', '-lcudart']
ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: ('nvcc return st
atus', 1, 'for cmd', 'nvcc -shared -g -O3 --compiler-bindir C:\\Program Files (x
86)\\Microsoft Visual Studio 12.0\\VC\\bin\\ -Xlinker /DEBUG -m32 -Xcompiler -LC
:\\TheanoPython\\python-2.7.6\\libs,-DCUDA_NDARRAY_CUH=d67f7c8a21306c67152a70a88
a837011,/Zi,/MD -IC:\\TheanoPython\\python-2.7.6\\lib\\site-packages\\theano\\sa
ndbox\\cuda -IC:\\TheanoPython\\python-2.7.6\\lib\\site-packages\\numpy\\core\\i
nclude -IC:\\TheanoPython\\python-2.7.6\\include -o C:\\Users\\Matej\\AppData\\L
ocal\\Theano\\compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3
_GenuineIntel-2.7.6-32\\cuda_ndarray\\cuda_ndarray.pyd mod.cu -LC:\\TheanoPython
\\python-2.7.6\\libs -LNone\\lib -LNone\\lib64 -LC:\\TheanoPython\\python-2.7.6
-lpython27 -lcublas -lcudart')
WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not availabl
e
In the latter error, several pop-up windows ask me how would I like to open (.res) file before error is thrown.
cl.exe is present in both folders (i.e. VS 2010 and VS 2013).
Finally, if I set VS 2013 in the environment path and set .theanorc contents as follows:
[global]
base_compiledir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
openmp=False
floatX = float32
device = gpu
[nvcc]
flags=-LC:\TheanoPython\python-2.7.6\libs
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\
[blas]
ldflags =
I get the following error:
c:\theanopython\python-2.7.6\include\pymath.h(22): warning: dllexport/dllimport conflict with "round"
c:\program files\nvidia gpu computing toolkit\cuda\v6.5\include\math_functions.h(2455): here; dllimport/dllexport dropped
mod.cu(954): warning: statement is unreachable
mod.cu(1114): error: namespace "std" has no member "min"
mod.cu(1145): error: namespace "std" has no member "min"
mod.cu(1173): error: namespace "std" has no member "min"
mod.cu(1174): error: namespace "std" has no member "min"
mod.cu(1317): error: namespace "std" has no member "min"
mod.cu(1318): error: namespace "std" has no member "min"
mod.cu(1442): error: namespace "std" has no member "min"
mod.cu(1443): error: namespace "std" has no member "min"
mod.cu(1742): error: namespace "std" has no member "min"
mod.cu(1777): error: namespace "std" has no member "min"
mod.cu(1781): error: namespace "std" has no member "min"
mod.cu(1814): error: namespace "std" has no member "min"
mod.cu(1821): error: namespace "std" has no member "min"
mod.cu(1853): error: namespace "std" has no member "min"
mod.cu(1861): error: namespace "std" has no member "min"
mod.cu(1898): error: namespace "std" has no member "min"
mod.cu(1905): error: namespace "std" has no member "min"
mod.cu(1946): error: namespace "std" has no member "min"
mod.cu(1960): error: namespace "std" has no member "min"
mod.cu(3750): error: namespace "std" has no member "min"
mod.cu(3752): error: namespace "std" has no member "min"
mod.cu(3784): error: namespace "std" has no member "min"
mod.cu(3786): error: namespace "std" has no member "min"
mod.cu(3789): error: namespace "std" has no member "min"
mod.cu(3791): error: namespace "std" has no member "min"
mod.cu(3794): error: namespace "std" has no member "min"
mod.cu(3795): error: namespace "std" has no member "min"
mod.cu(3836): error: namespace "std" has no member "min"
mod.cu(3838): error: namespace "std" has no member "min"
mod.cu(4602): error: namespace "std" has no member "min"
mod.cu(4604): error: namespace "std" has no member "min"
31 errors detected in the compilation of "C:/Users/Matej/AppData/Local/Temp/tmpxft_00001d84_00000000-10_mod.cpp1.ii".
ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: ('nvcc return status', 2, 'for cmd', 'nvcc -shared -g -O3 -Xlinker /DEBUG -m32 -Xcompiler -DCUDA_NDARRAY_CUH=d67f7c8a21306c67152a70a88a837011,/Zi,/MD -IC:\\TheanoPython\\python-2.7.6\\lib\\site-packages\\theano\\sandbox\\cuda -IC:\\TheanoPython\\python-2.7.6\\lib\\site-packages\\numpy\\core\\include -IC:\\TheanoPython\\python-2.7.6\\include -o C:\\Users\\Matej\\AppData\\Local\\Theano\\compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.6-32\\cuda_ndarray\\cuda_ndarray.pyd mod.cu -LC:\\TheanoPython\\python-2.7.6\\libs -LNone\\lib -LNone\\lib64 -LC:\\TheanoPython\\python-2.7.6 -lpython27 -lcublas -lcudart')
ERROR:theano.sandbox.cuda:Failed to compile cuda_ndarray.cu: ('nvcc return status', 2, 'for cmd', 'nvcc -shared -g -O3 -Xlinker /DEBUG -m32 -Xcompiler -DCUDA_NDARRAY_CUH=d67f7c8a21306c67152a70a88a837011,/Zi,/MD -IC:\\TheanoPython\\python-2.7.6\\lib\\site-packages\\theano\\sandbox\\cuda -IC:\\TheanoPython\\python-2.7.6\\lib\\site-packages\\numpy\\core\\include -IC:\\TheanoPython\\python-2.7.6\\include -o C:\\Users\\Matej\\AppData\\Local\\Theano\\compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.6-32\\cuda_ndarray\\cuda_ndarray.pyd mod.cu -LC:\\TheanoPython\\python-2.7.6\\libs -LNone\\lib -LNone\\lib64 -LC:\\TheanoPython\\python-2.7.6 -lpython27 -lcublas -lcudart')
mod.cu
['nvcc', '-shared', '-g', '-O3', '-Xlinker', '/DEBUG', '-m32', '-Xcompiler', '-DCUDA_NDARRAY_CUH=d67f7c8a21306c67152a70a88a837011,/Zi,/MD', '-IC:\\TheanoPython\\python-2.7.6\\lib\\site-packages\\theano\\sandbox\\cuda', '-IC:\\TheanoPython\\python-2.7.6\\lib\\site-packages\\numpy\\core\\include', '-IC:\\TheanoPython\\python-2.7.6\\include', '-o', 'C:\\Users\\Matej\\AppData\\Local\\Theano\\compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.6-32\\cuda_ndarray\\cuda_ndarray.pyd', 'mod.cu', '-LC:\\TheanoPython\\python-2.7.6\\libs', '-LNone\\lib', '-LNone\\lib64', '-LC:\\TheanoPython\\python-2.7.6', '-lpython27', '-lcublas', '-lcudart']
If I run import theano without the GPU option on, it runs without a problem. Also CUDA samples run without a problem.
Theano is a great tool for machine learning applications, yet I found that its installation on Windows is not trivial especially for beginners (like myself) in programming. In my case, I see 5-6x speedups of my scripts when run on a GPU so it was definitely worth the hassle.
I wrote this guide based on my installation procedure and is meant to be verbose and hopefully complete even for people with no prior understanding of building programs under Windows environment. Most of this guide is based on these instructions but I had to change some of the steps in order for it to work on my system. If there is anything that I do that may not be optimal or that doesn't work on your machine, please, let me know and I will try to modify this guide accordingly.
These are the steps (in order) I followed when installing Theano with GPU enabled on my Windows 8.1 machine:
CUDA Installation
CUDA can be downloaded from here. In my case, I chose 64-bit Notebook version for my NVIDIA Optimus laptop with Geforce 750m.
Verify that your installation was successful by launching deviceQuery from command line. In my case this was located in the following folder: C:\ProgramData\NVIDIA Corporation\CUDA Samples\v6.5\bin\win64\Release . If successful, you should see PASS at the end of the test.
Visual Studio 2010 Installation
I installed this via dreamspark. If you are a student you are entitled for a free version. If not, you can still install the Express version which should work just as well. After install is complete you should be able to call Visual Studio Command Prompt 2010 from the start menu.
Python Installation
At the time of writing, Theano on GPU only allows working with 32-bit floats and is primarily built for 2.7 version of Python. Theano requires most of the basic scientific Python libraries such as scipy and numpy. I found that the easiest way to install these was via WinPython. It installs all the dependencies in a self-contained folder which allows easy reinstall if something goes wrong in the installation process and you get some useful IDE tools such as ipython notebook and Spyder installed for free as well. For ease of use you might want to add the path to your python.exe and path to your Scripts folder in the environment variables.
Git installation
Found here.
MinGW Installation
Setup file is here. I checked all the base installation files during the installation process. This is required if you run into g++ error described below.
Cygwin installation
You can find it here. I basically used this utility only to extract PyCUDA tar file which is already provided in the base install (so the install should be straightforward).
Python distutils fix
Open msvc9compiler.py located in your /lib/distutils/ directory of your Python installation. Line 641 in my case reads: ld_args.append ('/IMPLIB:' + implib_file). Add the following after this line (same indentation):
ld_args.append('/MANIFEST')
PyCUDA installation
Source for PyCUDA is here.
Steps:
Open cygwin and navigate to the PyCUDA folder (i.e. /cygdrive/c/etc/etc) and execute tar -xzf pycuda-2012.1.tar.gz.
Open Visual Studio Command Prompt 2010 and navigate to the directory where tarball was extracted and execute python configure.py
Open the ./siteconf.py and change the values so that it reads (for CUDA 6.5 for instance):
BOOST_INC_DIR = []
BOOST_LIB_DIR = []
BOOST_COMPILER = 'gcc43'
USE_SHIPPED_BOOST = True
BOOST_PYTHON_LIBNAME = ['boost_python']
BOOST_THREAD_LIBNAME = ['boost_thread']
CUDA_TRACE = False
CUDA_ROOT = 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v6.5'
CUDA_ENABLE_GL = False
CUDA_ENABLE_CURAND = True
CUDADRV_LIB_DIR = ['${CUDA_ROOT}/lib/Win32']
CUDADRV_LIBNAME = ['cuda']
CUDART_LIB_DIR = ['${CUDA_ROOT}/lib/Win32']
CUDART_LIBNAME = ['cudart']
CURAND_LIB_DIR = ['${CUDA_ROOT}/lib/Win32']
CURAND_LIBNAME = ['curand']
CXXFLAGS = ['/EHsc']
LDFLAGS = ['/FORCE']
Execute the following commands at the VS2010 command prompt:
set VS90COMNTOOLS=%VS100COMNTOOLS%
python setup.py build
python setup.py install
Create this python file and verify that you get a result:
# from: http://documen.tician.de/pycuda/tutorial.html
import pycuda.gpuarray as gpuarray
import pycuda.driver as cuda
import pycuda.autoinit
import numpy
a_gpu = gpuarray.to_gpu(numpy.random.randn(4,4).astype(numpy.float32))
a_doubled = (2*a_gpu).get()
print a_doubled
print a_gpu
Install Theano
Open git bash shell and choose a folder in which you want to place Theano installation files and execute:
git clone git://github.com/Theano/Theano.git
python setup.py install
Try opening python in VS2010 command prompt and run import theano
If you get a g++ related error, open MinGW msys.bat in my case installed here: C:\MinGW\msys\1.0 and try importing theano in MinGW shell. Then retry importing theano from VS2010 Command Prompt and it should be working now.
Create a file in WordPad (NOT Notepad!), name it .theanorc.txt and put it in C:\Users\Your_Name\ or wherever your users folder is located:
#!sh
[global]
device = gpu
floatX = float32
[nvcc]
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin
# flags=-m32 # we have this hard coded for now
[blas]
ldflags =
# ldflags = -lopenblas # placeholder for openblas support
Create a test python script and run it:
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = 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 xrange(iters):
r = f()
t1 = time.time()
print 'Looping %d times took' % iters, t1 - t0, 'seconds'
print 'Result is', 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'
Verify you got Used the gpu at the end and you're done!
Here are my simple steps for installing theano on a
64-bit windows 10 machine. It's tested on the code listed here
(All installation are with default installation path)
install anaconda python 3.x distribution (it already includes numpy,
scipy, matlibplot, etc.)
run 'conda install mingw libpython' in command-line
install theano by downloading it from the official website and do `python setup.py install'
install lastest CUDA toolkit for 64-bit windows 10 (now is 7.5)
install visual studio 2013 (free for windows 10)
create .theanorc.txt file under %USERPROFILE% path and here are
the content in the .theanorc.txt file to run theano with GPU
[global]
floatX = float32
device = gpu
[nvcc]
fastmath = True
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe
[cuda]
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5
Here's a guide to installing theano with CUDA on 64-bit Windows.
It seems straightforward, but I have not actually tested it to ensure that it works.
http://pavel.surmenok.com/2014/05/31/installing-theano-with-gpu-on-windows-64-bit/
Following the tutorial by Matt, I ran into issues with nvcc.
I needed to add the path to VS2010 executables in nvcc.profile (you can find it in the cuda bin folder):
"compiler-bindir = C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64"
In case you want to upgrade to MS Visual Studio 2012 and CUDA 7 on Windows 8.1 x64, check out this tutorial here:
http://machinelearning.berlin/?p=383
It should work as long as you stick to it exactly.
All the best
Christian
I could compile the cu files by adding the required dependencies in the nvcc profile located in “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\bin\nvcc.profile”
I modified the include and the lib path and it started working.
INCLUDES += “-I$(TOP)/include” $(SPACE) “-IC:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/include” $(SPACE) “-IC:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include” $(SPACE)
LIBRARIES =+ $(SPACE) “/LIBPATH:$(TOP)/lib/$(_WIN_PLATFORM_)” $(SPACE) “/LIBPATH:C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/lib/amd64” $(SPACE) “/LIBPATH:C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64” $(SPACE)
I have made a full documentation of the install, hope it helps https://planetanacreon.wordpress.com/2015/10/09/install-theano-on-windows-8-1-with-visual-studio-2013-cuda-7-5/
I used this guide, and it was quite helpful.
What many of Windows Theano guides only mention in passing (or not at all) is that you will need to compile theano from mingw shell, not from your IDE.
I ran mingw-w64.bat, and from there "python" and "import theano". Only after that importing it from pycharm works.
Additionally, official instructions on deeplearning.net are bad because they tell you to use CUDA 5.5, but it won't work with newer video cards.
The comments are also quite helpful. If it complains about missing crtdefs.h or basetsd.h, do what Sunando's answer says. If AFTER THAT it still complains that identifier "Iunknown" is undefined in objbase.h, stick the following in
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\objbase.h file, on line 236:
#include <wtypes.h>
#include <unknwn.h>
I had to do this last part to make it work with bleeding edge install (required for parts of Keras).
I also wrote a list of things that worked for me, here:
http://acoupleofrobots.com/everything/?p=2238
This is for 64 bit version.