1
1
# Build from source on Windows
2
2
3
- Build a TensorFlow * pip* package from source and install it on Windows.
3
+ Build a TensorFlow * pip* package from the source and install it on Windows.
4
4
5
5
Note: We already provide well-tested, pre-built
6
6
[ TensorFlow packages] ( ./pip.md ) for Windows systems.
@@ -20,6 +20,7 @@ variable.
20
20
Install the TensorFlow * pip* package dependencies:
21
21
22
22
<pre class =" devsite-click-to-copy " >
23
+ <code class =" devsite-terminal tfo-terminal-windows " >pip3 install -U pip</code >
23
24
<code class =" devsite-terminal tfo-terminal-windows " >pip3 install -U six numpy wheel packaging</code >
24
25
<code class =" devsite-terminal tfo-terminal-windows " >pip3 install -U keras_preprocessing --no-deps</code >
25
26
</pre >
@@ -47,22 +48,35 @@ build TensorFlow. If MSYS2 is installed to `C:\msys64`, add
47
48
run:
48
49
49
50
<pre class =" devsite-terminal tfo-terminal-windows devsite-click-to-copy " >
51
+ pacman -Syu (requires a console restart)
50
52
pacman -S git patch unzip
53
+ pacman -S git patch unzip rsync
51
54
</pre >
52
55
53
- ### Install Visual C++ Build Tools 2019
56
+ Note: Clang will be the preferred compiler to build TensorFlow CPU wheels on the Windows Platform starting with TF 2.16.1 The currently supported version is LLVM/clang 17.0.6.
54
57
55
- Install the * Visual C++ build tools 2019* . This comes with * Visual Studio 2019*
58
+ Note: To build with Clang on Windows, it is required to install both LLVM and Visual C++ Build tools as although Windows uses clang-cl.exe as the compiler, Visual C++ Build tools are needed to link to Visual C++ libraries
59
+
60
+ ### Install Visual C++ Build Tools 2022
61
+
62
+ Install the * Visual C++ build tools 2022* . This comes with * Visual Studio Community 2022*
56
63
but can be installed separately:
57
64
58
65
1 . Go to the
59
66
[ Visual Studio downloads] ( https://visualstudio.microsoft.com/downloads/ ) {:.external},
60
- 2 . Select * Redistributables and Build Tools* ,
67
+ 2 . Select * Tools for Visual Studio or Other Tools, Framework and Redistributables * ,
61
68
3 . Download and install:
62
- - * Microsoft Visual C++ 2019 Redistributable*
63
- - * Microsoft Build Tools 2019*
69
+ - * Build Tools for Visual Studio 2022*
70
+ - * Microsoft Visual C++ Redistributables for Visual Studio 2022*
71
+
72
+ Note: TensorFlow is tested against the * Visual Studio Community 2022* .
73
+
74
+ ### Install LLVM
75
+
76
+ 1 . Go to the
77
+ [ LLVM downloads] ( https://github.com/llvm/llvm-project/releases/ ) {:.external},
78
+ 2 . Download and install Windows-compatible LLVM in C:/Program Files/LLVM e.g., LLVM-17.0.6-win64.exe
64
79
65
- Note: TensorFlow is tested against the * Visual Studio 2019* .
66
80
67
81
### Install GPU support (optional)
68
82
@@ -94,31 +108,32 @@ Key Point: If you're having build problems on the latest development branch, try
94
108
a release branch that is known to work.
95
109
96
110
## Optional: Environmental Variable Set Up
97
- Run following commands before running build command to avoid issue with package creation:
98
- (If the below commands were set up while installing the packages, please ignore them). Run ` set ` check if all the paths were set correctly, run ` echo %Environmental Variable% ` e.g., ` echo %BAZEL_VC% ` to check path set up for a specific Environmental Variable
111
+ Run the following commands before running the build command to avoid issues with package creation:
112
+ (If the below commands were set up while installing the packages, please ignore them). Run ` set ` to check if all the paths were set correctly, run ` echo %Environmental Variable% ` e.g., ` echo %BAZEL_VC% ` to check the path set up for a specific Environmental Variable
99
113
100
114
Python path set up issue [ tensorflow: issue #59943] ( https://github.com/tensorflow/tensorflow/issues/59943 ) ,[ tensorflow: issue #9436] ( https://github.com/tensorflow/tensorflow/issues/9436 ) ,[ tensorflow: issue #60083] ( https://github.com/tensorflow/tensorflow/issues/60083 )
101
115
102
116
<pre class =" devsite-terminal tfo-terminal-windows devsite-click-to-copy " >
103
- set PATH=path/to/python # [e.g. (C:/Python310 )]
104
- set PATH=path/to/python/Scripts # [e.g. (C:/Python310 /Scripts)]
117
+ set PATH=path/to/python;%PATH% # [e.g. (C:/Python311 )]
118
+ set PATH=path/to/python/Scripts;%PATH% # [e.g. (C:/Python311 /Scripts)]
105
119
set PYTHON_BIN_PATH=path/to/python_virtualenv/Scripts/python.exe
106
120
set PYTHON_LIB_PATH=path/to/python virtualenv/lib/site-packages
107
121
set PYTHON_DIRECTORY=path/to/python_virtualenv/Scripts
108
122
</pre >
109
123
110
- Bazel/MSVC path set up issue [ tensorflow: issue #54578] ( https://github.com/tensorflow/tensorflow/issues/54578 )
124
+ Bazel/MSVC/CLANG path set up issue [ tensorflow: issue #54578] ( https://github.com/tensorflow/tensorflow/issues/54578 )
111
125
112
126
<pre class =" devsite-terminal tfo-terminal-windows devsite-click-to-copy " >
113
127
set BAZEL_SH=C:/msys64/usr/bin/bash.exe
114
- set BAZEL_VS=C:/Program Files(x86)/Microsoft Visual Studio/2019/BuildTools
115
- set BAZEL_VC=C:/Program Files(x86)/Microsoft Visual Studio/2019/BuildTools/VC
128
+ set BAZEL_VS=C:/Program Files/Microsoft Visual Studio/2022/BuildTools
129
+ set BAZEL_VC=C:/Program Files/Microsoft Visual Studio/2022/BuildTools/VC
130
+ set Bazel_LLVM=C:/Program Files/LLVM (explicitly tell Bazel where LLVM is installed by BAZEL_LLVM, needed while using CLANG)
131
+ set PATH=C:/Program Files/LLVM/bin;%PATH% (Optional, needed while using CLANG as Compiler)
116
132
</pre >
117
133
118
-
119
134
## Optional: Configure the build
120
135
121
- TensorFlow builds are configured by the ` .bazelrc ` file in the respoitory 's
136
+ TensorFlow builds are configured by the ` .bazelrc ` file in the repository 's
122
137
root directory. The ` ./configure ` or ` ./configure.py ` scripts can be used to
123
138
adjust common settings.
124
139
@@ -138,21 +153,27 @@ differ):
138
153
<h4 class =" showalways " >View sample configuration session</h4 >
139
154
<pre class =" devsite-terminal tfo-terminal-windows " >
140
155
python ./configure.py
141
- You have bazel 5.3.0 installed.
142
- Please specify the location of python. [Default is C:\Python310\python.exe]:
156
+ You have bazel 6.5.0 installed.
157
+ Please specify the location of python. [Default is C:\Python311\python.exe]:
158
+
143
159
Found possible Python library paths:
144
- C:\Python310 \lib\site-packages
145
- Please input the desired Python library path to use. Default is [C:\Python310 \lib\site-packages]
160
+ C:\Python311 \lib\site-packages
161
+ Please input the desired Python library path to use. Default is [C:\Python311 \lib\site-packages]
146
162
147
163
Do you wish to build TensorFlow with ROCm support? [y/N]:
148
164
No ROCm support will be enabled for TensorFlow.
149
165
150
-
151
166
WARNING: Cannot build with CUDA support on Windows.
152
- Starting in TF 2.11, CUDA build is not supported for Windows. For using TensorFlow GPU on Windows, you will need to build/install TensorFlow in WSL2.
167
+ Starting in TF 2.11, CUDA build is not supported for Windows. To use TensorFlow GPU on Windows, you will need to build/install TensorFlow in WSL2.
153
168
154
- Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is /arch:AVX]:
169
+ Do you want to use Clang to build TensorFlow? [Y/n]:
170
+ Add "--config=win_clang" to compile TensorFlow with CLANG.
155
171
172
+ Please specify the path to clang executable. [Default is C:\Program Files\LLVM\bin\clang.EXE]:
173
+
174
+ You have Clang 17.0.6 installed.
175
+
176
+ Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is /arch:AVX]:
156
177
157
178
Would you like to override eigen strong inline for some C++ compilation to reduce the compilation time? [Y/n]:
158
179
Eigen strong inline overridden.
@@ -170,13 +191,12 @@ Preconfigured Bazel build configs. You can use any of the below by adding "--con
170
191
Preconfigured Bazel build configs to DISABLE default on features:
171
192
--config=nogcp # Disable GCP support.
172
193
--config=nonccl # Disable NVIDIA NCCL support.
173
-
174
194
</pre >
175
195
</section >
176
196
177
197
## Build and install the pip package
178
198
179
- The pip package gets built in two steps. A ` bazel build ` commands creates a
199
+ The pip package is built in two steps. A ` bazel build ` command creates a
180
200
"package-builder" program. You then run the package-builder to create the
181
201
package.
182
202
@@ -187,15 +207,23 @@ tensorflow:master repo has been updated to build 2.x by default.
187
207
` bazel build ` to create the TensorFlow package-builder.
188
208
189
209
<pre class =" devsite-terminal tfo-terminal-windows devsite-click-to-copy " >
190
- bazel build //tensorflow/tools/pip_package:build_pip_package
210
+ bazel build //tensorflow/tools/pip_package:wheel
191
211
</pre >
192
212
193
213
#### CPU-only
194
214
195
215
Use ` bazel ` to make the TensorFlow package builder with CPU-only support:
196
216
217
+ ##### Build with MSVC
218
+ <pre class =" devsite-terminal tfo-terminal-windows devsite-click-to-copy " >
219
+ bazel build --config=opt --repo_env=TF_PYTHON_VERSION=3.11 //tensorflow/tools/pip_package:wheel --repo_env=WHEEL_NAME=tensorflow_cpu
220
+ </pre >
221
+
222
+ ##### Build with CLANG
223
+ Use --config=` win_clang ` to build TenorFlow with the CLANG Compiler:
224
+
197
225
<pre class =" devsite-terminal tfo-terminal-windows devsite-click-to-copy " >
198
- bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
226
+ bazel build --config=win_clang --repo_env=TF_PYTHON_VERSION=3.11 //tensorflow/tools/pip_package:wheel --repo_env=WHEEL_NAME=tensorflow_cpu
199
227
</pre >
200
228
201
229
#### GPU support
@@ -217,7 +245,7 @@ bazel clean --expunge
217
245
218
246
#### Bazel build options
219
247
220
- Use this option when building to avoid issue with package creation:
248
+ Use this option when building to avoid issues with package creation:
221
249
[ tensorflow: issue #22390] ( https://github.com/tensorflow/tensorflow/issues/22390 )
222
250
223
251
<pre class =" devsite-terminal tfo-terminal-windows devsite-click-to-copy " >
@@ -236,33 +264,37 @@ to suppress nvcc warning messages.
236
264
237
265
### Build the package
238
266
239
- The ` bazel build ` command creates an executable named ` build_pip_package ` —this
240
- is the program that builds the ` pip ` package. For example, the following builds
241
- a ` .whl ` package in the ` C:/tmp/tensorflow_pkg ` directory:
267
+ To build a pip package, you need to specify the --repo_env=WHEEL_NAME flag.
268
+ Depending on the provided name, the package will be created. For example:
242
269
243
- <pre class =" devsite-terminal tfo-terminal-windows devsite-click-to-copy " >
244
- bazel-bin\tensorflow\tools\pip_package\build_pip_package C:/tmp/tensorflow_pkg
270
+ To build tensorflow CPU package:
271
+ <pre class =" devsite-terminal devsite-click-to-copy " >
272
+ bazel build //tensorflow/tools/pip_package:wheel --repo_env=WHEEL_NAME=tensorflow_cpu
245
273
</pre >
246
274
247
- Although it is possible to build both CUDA and non-CUDA configs under the
248
- same source tree, we recommend running ` bazel clean ` when switching between
249
- these two configurations in the same source tree.
275
+ To build nightly package, set ` tf_nightly ` instead of ` tensorflow ` , e.g.
276
+ to build CPU nightly package:
277
+ <pre class =" devsite-terminal devsite-click-to-copy " >
278
+ bazel build //tensorflow/tools/pip_package:wheel --repo_env=WHEEL_NAME=tf_nightly_cpu
279
+ </pre >
280
+
281
+ As a result, generated wheel will be located in
282
+ <pre class =" devsite-terminal devsite-click-to-copy " >
283
+ bazel-bin/tensorflow/tools/pip_package/wheel_house/
284
+ </pre >
250
285
251
286
252
287
### Install the package
253
288
254
289
The filename of the generated ` .whl ` file depends on the TensorFlow version and
255
- your platform. Use ` pip3 install` to install the package, for example:
290
+ your platform. Use ` pip install` to install the package, for example:
256
291
257
- <pre class =" devsite-terminal tfo-terminal-windows prettyprint lang-bsh " >
258
- pip3 install C:/tmp/tensorflow_pkg/tensorflow-<var >version</var >-<var >tags</var >.whl
259
-
260
- e.g., pip3 install C:/tmp/tensorflow_pkg/tensorflow-2.12.0-cp310-cp310-win_amd64.whl
292
+ <pre class =" devsite-terminal prettyprint lang-bsh " >
293
+ pip install bazel-bin/tensorflow/tools/pip_package/wheel_house/tensorflow-<var >version</var >-<var >tags</var >.whl
261
294
</pre >
262
295
263
296
Success: TensorFlow is now installed.
264
297
265
-
266
298
## Build using the MSYS shell
267
299
268
300
TensorFlow can also be built using the MSYS shell. Make the changes listed
@@ -309,7 +341,7 @@ Note: Starting in TF 2.11, CUDA build is not supported for Windows. For using Te
309
341
310
342
<table >
311
343
<tr ><th >Version</th ><th >Python version</th ><th >Compiler</th ><th >Build tools</th ></tr >
312
- <tr ><td >tensorflow-2.16.1</td ><td >3.9-3.12</td ><td >MSVC 2019 </td ><td >Bazel 6.5.0</td ></tr >
344
+ <tr ><td >tensorflow-2.16.1</td ><td >3.9-3.12</td ><td >CLANG 17.0.6 </td ><td >Bazel 6.5.0</td ></tr >
313
345
<tr ><td >tensorflow-2.15.0</td ><td >3.9-3.11</td ><td >MSVC 2019</td ><td >Bazel 6.1.0</td ></tr >
314
346
<tr ><td >tensorflow-2.14.0</td ><td >3.9-3.11</td ><td >MSVC 2019</td ><td >Bazel 6.1.0</td ></tr >
315
347
<tr ><td >tensorflow-2.12.0</td ><td >3.8-3.11</td ><td >MSVC 2019</td ><td >Bazel 5.3.0</td ></tr >
0 commit comments