Caffe安裝中多版本protoc選擇問題_caffe

來源:互聯網
上載者:User

作為一個實驗室資源特別緊缺,好幾個人在伺服器上共用一個路徑的苦逼研究生,面對大家都需要跑caffe的時候就會非常蛋疼。特別是有些人亂七八糟的裝不同版本的protobuf,安裝在不同路徑下,該如何選取特定的版本進行caffe編譯呢。
我是linux零基礎+caffe零基礎,查了好多資料,勉強拼湊出來了如何選擇protobuf版本的解決辦法。

例如我們的伺服器上有兩個版本的protobuf,版本3.1.0安裝在usr/local/bin下,版本3.0.0安裝在$HOME/anaconda2/bin下,
在terminal中運行

sudo protoc --version

會顯示目前的版本是3.1.0,路徑指向的是usr/local/bin

protoc --version

就會顯示版本是3.0.0,路徑指向$HOME/anaconda2/bin

編譯caffe用

sudo make all -j4

就會出現這一個常見的問題

In file included from .build_release/src/caffe/proto/caffe.pb.cc:5:0:.build_release/src/caffe/proto/caffe.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is #error This file was generated by a newer version of protoc which is  ^.build_release/src/caffe/proto/caffe.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update #error incompatible with your Protocol Buffer headers.  Please update  ^.build_release/src/caffe/proto/caffe.pb.h:14:2: error: #error your headers. #error your headers.  ^  ...

這是一個經典問題,所有人都會跟你說重裝protobuf吧,比如運行

sudo apt-get install libprotobuf-dev

然而對於一個需要低版本的protobuf的人這句命令列沒卵用。

由於我的$HOME/anaconda2/bin中有合適的版本,所以我是打算直接用這裡的protobuf,通過查資料,瞭解到sudo的時候,預設的環境變數在/etc/sudoers檔案中,一般來說sudo會重設$PATH,而sudoers檔案有這樣一行

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

所以 sudo的時候$PATH就是從這裡讀取,因此我只需添加我的路徑就可以了,注意要把路徑添加在其他版本路徑的前面,位置決定了讀取順序

#Defaults   secure_path="/usr/local/sbin:/usr/local/bin:\$HOME/anaconda2/bin:/usr/sbin:/usr/bin:/sbin:/bin"

注意sudoers檔案很重要,修改前記得備份

secure_path是即時生效的,這時候再次運行sudo使用的版本就變成了我需要的3.0.0版本。
這算是解決了第一步問題吧……後面還有各種問題,一點一點記錄吧。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.