2018-05-22-源碼安裝TensorFlow

使用virtualenv安裝了tensorflow烈菌,但運(yùn)行的時(shí)候發(fā)現(xiàn)CPU可以支持AVX2和FMV霉囚,但需要從源碼重新構(gòu)建。好吧,那就開(kāi)始吧~

參考:

從源代碼安裝 TensorFlow

1. 環(huán)境

系統(tǒng):macOS High Sierra 10.13.4

python:2.7.15(系統(tǒng)自帶)

2. 準(zhǔn)備

2.1 避免沖突

我在前面已經(jīng)用virtualenv創(chuàng)建了tensorflow的環(huán)境项乒,此前創(chuàng)建的目錄名稱(chēng)“tensorflow”,怕產(chǎn)生沖突梁沧,將虛擬環(huán)境的目錄名稱(chēng)修改為“vir-tensorflow”

2.2 克隆代碼庫(kù)

打開(kāi)終端檀何,輸入以下命令:

$ git clone https://github.com/tensorflow/tensorflow

此時(shí),會(huì)在用戶目錄下創(chuàng)建一個(gè)“tensorflow”的目錄(幸虧剛剛該虛擬環(huán)境目錄的命名了~~)

下載的時(shí)間比較長(zhǎng)廷支,請(qǐng)耐心等待~~快受不了公司的網(wǎng)速了F导!A蹬摹6饪住!

2.3 針對(duì)macOS準(zhǔn)備環(huán)境

2.3.1 安裝bazel

Installing Bazel on macOS

使用brew安裝:

brew install bazel? ? ? ? #安裝

bazel version? ? ? ? ? ? ? #查看是否安裝成功

brew upgrade bazel? ?#升級(jí)版本

2.3.2 安裝python依賴(lài)項(xiàng)

必須安裝軟件包:

six

numpy:數(shù)值處理

wheel:管理wheel格式的python壓縮包

使用pip來(lái)安裝:

$ sudo pip install six numpy wheel

當(dāng)前版本:

six——1.11.0施敢,numpy——1.14.3周荐,wheel——0.31.0

2.4 安裝配置

2.4.1 軟件包配置

克隆源碼庫(kù)到本地后,在根目錄中包含有一個(gè)名為“configure”的bash腳本僵娃。必須先運(yùn)行該腳本概作,然后才能創(chuàng)建pip軟件包并安裝TensorFlow。

$ cd /xxxx/tensorflow

$ ./configure

進(jìn)入tensorflow源碼樹(shù)的根目錄默怨,執(zhí)行configure的bash腳本讯榕。

此時(shí)configure腳本會(huì)向您提出若干問(wèn)題。我選擇默認(rèn)值先壕,針對(duì)本機(jī)CPU類(lèi)型優(yōu)化所生成的代碼瘩扼,但是這樣構(gòu)建出來(lái)的TensorFlow是無(wú)法在其他類(lèi)型的CPU上運(yùn)行的谆甜。

以下是我運(yùn)行configure腳本時(shí)的問(wèn)題選擇:

Extracting Bazel installation...

You have bazel 0.13.0-homebrew installed.

Please specify the location of python. [Default is /usr/local/opt/python@2/bin/python2.7]: /usr/bin/python2.7

Found possible Python library paths:

? /Library/Python/2.7/site-packages

Please input the desired Python library path to use.? Default is [/Library/Python/2.7/site-packages]

/Library/Python/2.7/site-packages

Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: N

No Google Cloud Platform support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: N

No Hadoop File System support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: N

No Amazon S3 File System support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Apache Kafka Platform support? [Y/n]: N

No Apache Kafka Platform support will be enabled for TensorFlow.

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 GDR support? [y/N]: N

No GDR support will be enabled for TensorFlow.

Do you wish to build TensorFlow with VERBS support? [y/N]: N

No VERBS support will be enabled for TensorFlow.

Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: N

No OpenCL SYCL 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.

Do you wish to download a fresh release of clang? (Experimental) [y/N]: N

Clang will not be downloaded.

Do you wish to build TensorFlow with MPI support? [y/N]: N

No MPI 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]: -march=native

Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: N

Not configuring the WORKSPACE for Android builds.

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

--config=mkl # Build with MKL support.

--config=monolithic # Config for mostly static monolithic build.

Configuration finished

2.4.2 軟件包構(gòu)建

配置后垃僚,進(jìn)行構(gòu)建:

$ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

報(bào)錯(cuò)了<隆!W还住T匝唷!

Starting local Bazel server and connecting to it...

................

WARNING: /private/var/tmp/_bazel_yujianwen/7cea4d7c61741771d65fc25d431ce59d/external/protobuf_archive/WORKSPACE:1: Workspace name in /private/var/tmp/_bazel_yujianwen/7cea4d7c61741771d65fc25d431ce59d/external/protobuf_archive/WORKSPACE (@com_google_protobuf) does not match the name given in the repository's definition (@protobuf_archive); this will cause a build error in future versions

ERROR: /private/var/tmp/_bazel_yujianwen/7cea4d7c61741771d65fc25d431ce59d/external/local_config_cc/BUILD:50:5: in apple_cc_toolchain rule @local_config_cc//:cc-compiler-armeabi-v7a: Xcode version must be specified to use an Apple CROSSTOOL. If your Xcode version has changed recently, try: "bazel clean --expunge" to re-run Xcode configuration

ERROR: While resolving toolchains for target //tensorflow/tools/pip_package:simple_console: Analysis of target '@local_config_cc//:cc-compiler-armeabi-v7a' failed; build aborted

ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted: Analysis of target '@local_config_cc//:cc-compiler-armeabi-v7a' failed; build aborted

INFO: Elapsed time: 17.909s

INFO: 0 processes.

FAILED: Build did NOT complete successfully (64 packages loaded)

? ? currently loading: tensorflow/python ... (3 packages)

Error: Xcode version must be specified to use an Apple CROSSTOOL

處理:

應(yīng)該是Xcode使用版本與系統(tǒng)版本不一致改淑,需要修改Xcode版本

本機(jī)Xocde版本:9.3.1

$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

$ bazel clean --expunge

執(zhí)行以上指令后碍岔,重新構(gòu)建,沒(méi)有Error朵夏,可以往下執(zhí)行~~~

過(guò)了一個(gè)中午蔼啦,還是構(gòu)建過(guò)程還是出現(xiàn)error,一共20個(gè)仰猖。停止了~~~

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末捏肢,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子饥侵,更是在濱河造成了極大的恐慌鸵赫,老刑警劉巖,帶你破解...
    沈念sama閱讀 212,029評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件躏升,死亡現(xiàn)場(chǎng)離奇詭異辩棒,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)膨疏,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,395評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門(mén)一睁,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人佃却,你說(shuō)我怎么就攤上這事者吁。” “怎么了双霍?”我有些...
    開(kāi)封第一講書(shū)人閱讀 157,570評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵砚偶,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我洒闸,道長(zhǎng)染坯,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,535評(píng)論 1 284
  • 正文 為了忘掉前任丘逸,我火速辦了婚禮,結(jié)果婚禮上仲锄,老公的妹妹穿的比我還像新娘镣奋。我一直安慰自己,他們只是感情好哈垢,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,650評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著求泰,像睡著了一般拜秧。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上聊替,一...
    開(kāi)封第一講書(shū)人閱讀 49,850評(píng)論 1 290
  • 那天肩钠,我揣著相機(jī)與錄音价匠,去河邊找鬼坡氯。 笑死手形,一個(gè)胖子當(dāng)著我的面吹牛库糠,可吹牛的內(nèi)容都是我干的鳞骤。 我是一名探鬼主播篙梢,決...
    沈念sama閱讀 39,006評(píng)論 3 408
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼榴嗅,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼绪励!你這毒婦竟也來(lái)了疏魏?” 一聲冷哼從身側(cè)響起官份,我...
    開(kāi)封第一講書(shū)人閱讀 37,747評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后们陆,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體杂腰,經(jīng)...
    沈念sama閱讀 44,207評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡皆刺,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,536評(píng)論 2 327
  • 正文 我和宋清朗相戀三年忙干,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了捐迫。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,683評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡爱葵,死狀恐怖施戴,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情钧惧,我是刑警寧澤暇韧,帶...
    沈念sama閱讀 34,342評(píng)論 4 330
  • 正文 年R本政府宣布,位于F島的核電站浓瞪,受9級(jí)特大地震影響懈玻,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜乾颁,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,964評(píng)論 3 315
  • 文/蒙蒙 一涂乌、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧英岭,春花似錦湾盒、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,772評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)毅人。三九已至,卻和暖如春尖殃,著一層夾襖步出監(jiān)牢的瞬間丈莺,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,004評(píng)論 1 266
  • 我被黑心中介騙來(lái)泰國(guó)打工送丰, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留缔俄,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,401評(píng)論 2 360
  • 正文 我出身青樓器躏,卻偏偏與公主長(zhǎng)得像俐载,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子登失,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,566評(píng)論 2 349

推薦閱讀更多精彩內(nèi)容