windows10下如何進行源碼編譯安裝tensorflow


1.獲取python3.5.x

https://www.python.org/ftp/python/3.5.4/python-3.5.4-amd64.exe

2.安裝python3.5.x,默認安裝即可,安裝后將路徑添加到環境變量PATH中

筆者安裝后python的路徑為:C:\Users\jello\AppData\Local\Programs\Python\Python35

pip路徑為:C:\Users\jello\AppData\Local\Programs\Python\Python35\Scripts

3.安裝tensorflow的依賴包

pip3 install six numpy wheel

pip3 install keras_applications==1.0.6 --no-deps
pip3 install keras_preprocessing==1.0.5 --no-deps

4.獲取MSYS2

http://repo.msys2.org/distrib/x86_64/msys2-x86_64-20180531.exe

5.安裝MSYS2

5.1添加路徑C:\msys64\usr\bin到PATH環境變量

5.2安裝git patch unzip等軟件 

pacman -S git patch unzip

6.獲取Visual C++ Build Tools 2015

https://www.microsoft.com/en-us/download/details.aspx?id=48159

7.安裝Visual C++ Build Tools 2015

8.獲取Microsoft Visual C++ 2015 Redistributable Update 3

https://www.microsoft.com/en-us/download/details.aspx?id=53587

9.安裝Microsoft Visual C++ 2015 Redistributable Update 3 (如果安裝無法進行,可能有其它版本,卸載最新版本即可,如安裝2013 和2017,那么卸載2017這個版本即可)

10.獲取Visual Studio 2015

https://download.microsoft.com/download/b/e/d/bedddfc4-55f4-4748-90a8-ffe38a40e89f/vs2015.3.com_enu.iso

11.安裝Visual Studio 2015

 

12.獲取bazel

https://github.com/bazelbuild/bazel/releases (從此鏈接選擇合適的版本即可)

13.安裝bazel (依賴MSYS2和Visual C++ Build Tools 2015),安裝方法如下

將文件bazel-0.21.0-windows-x86_64重命名為bazel,然后將文件bazel放到C:\msys64\usr\bin目錄下

14.獲取tensorflow源碼

git clone https://github.com/tensorflow/tensorflow.git (如果使用git無法獲取源碼,提示fatal: BUG: disabling cancellation: Invalid argument,那么直接去github上下載源碼壓縮包即可)
cd tensorflow

git checkout remotes/origin/r1.13

15.配置tensorflow

python ./configure.py

筆者的配置如下:

C:\Users\jello\tensorflow>python ./configure.py
WARNING: The following rc files are no longer being read, please transfer their contents or import their path into one of the standard rc files:
nul
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
INFO: Invocation ID: 89e98bd0-d528-40ac-ac67-87aa0682b890
You have bazel 0.21.0 installed.
Please specify the location of python. [Default is C:\Users\jello\AppData\Local\Programs\Python\Python35\python.exe]:


Found possible Python library paths:
C:\Users\jello\AppData\Local\Programs\Python\Python35\lib\site-packages
Please input the desired Python library path to use. Default is [C:\Users\jello\AppData\Local\Programs\Python\Python35\lib\site-packages]

Do you wish to build TensorFlow with XLA JIT support? [y/N]: n
No XLA JIT support will be enabled for TensorFlow.

Do you wish to build TensorFlow with ROCm support? [y/N]: n
No ROCm support will be enabled for TensorFlow.

Do you wish to build TensorFlow with CUDA support? [y/N]: n
No CUDA support will be enabled for TensorFlow.

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is /arch:AVX]:

Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.

16.構建tensorflow pip包

    方法一:在cmd中構建

    

16.1 設置變量
set BAZEL_VS=C:\Program Files (x86)\Microsoft Visual Studio 14.0  (這個變量是用來告知bazel,Visual Studio所安裝的目錄)
16.2 bazel build -c opt --copt=-msse4.1 --copt=-msse4.2 --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-O3 //tensorflow/tools/pip_package:build_pip_package
16.3 bazel-bin\tensorflow\tools\pip_package\build_pip_package C:/tmp/tensorflow_pkg
 
        
方法二:在MSYS2中構建
16.1 啟動MSYS2
16.2 禁用MSYS2路徑轉換
export MSYS_NO_PATHCONV=1
export MSYS2_ARG_CONV_EXCL="*"
16.3 設置環境變量
export PATH="/c/Users/jello/AppData/Local/Programs/Python/Python35:$PATH" (將python的路徑加入環境變量PATH中)

16.4 獲取tensorflow源碼
16.5 bazel build -c opt --copt=-msse4.1 --copt=-msse4.2 --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-O3 //tensorflow/tools/pip_package:build_pip_package
16.6 bazel-bin\tensorflow\tools\pip_package\build_pip_package C:/tmp/tensorflow_pkg
 
        

17.安裝tensorflow

pip3 install C:/tmp/tensorflow_pkg/tensorflow-version-cp35-cp35m-win_amd64.whl

18.參考資料

https://www.tensorflow.org/install/source_windows


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM