標籤:必須 bin 安裝python code 找不到 .sh fail anaconda 更新
首先介紹下window編譯caffe2整體流程:
說明:如果不需要python支援只需3、4即可,而且編譯亦不會出現問題。
1. 安裝python2.7,。
我使用的是anaconda python2.7環境,要將python路徑添加到系統路徑(PYTH)。
2.python一些必要庫的安裝,如numpy、pybind11(是否必須未驗證??)
具體其他依賴庫參見網址:
https://caffe2.ai/docs/getting-started.html?platform=windows&configuration=compile
我安裝的庫:
pip install future hypothesis numpy protobuf six
pip install flask glog graphviz jupyter matplotlib pydot python-nvd3 pyyaml requests scikit-image scipy setuptools tornado
pip install pybind11
3. 運行找到下載好的caffe2\scripts\build_host_protoc.sh
4.運行caffe2\scripts\build_windows.bat
此時要注意:
如果需要python支援需要將“-DBUILD_PYTHON=OFF^”設定為“-DBUILD_PYTHON=ON^”
如果為OFF大家可以放心編譯,設定為ON後會遇到下面描述的問題。
遇到問題及解決方案:
1. 問題找不到numpy,確定python中已經安裝
類似:Could NOT find NumPy (missing: NUMPY_INCLUDE_DIR NUMPY_VERSION) 錯誤。
解決方案:
這時將以前的numpy刪除,重新安裝numpy即可解決問題。
刪除: pip uninstall numpy
安裝:pip install nump
2.問題:
CMake summary output
I am installing caffe2 on win10 and it takes me almost a whole day. There are many missing argvs and errors in build_windows.bat
. I doubt that the script has not been tested before.
Now I have another problem afer executing build_windows.bat
:
ERROR Failed to remove indentation from:
"""
from distutils import sysconfig print(sysconfig.get_python_lib(prefix=‘‘))
"""
Python dedent failed with error code: 系統找不到指定的檔案。(system can not find specified file)
CMake Error at cmake/Utils.cmake:177 (message):
Python dedent failed with error code: 系統找不到指定的檔案。(system can not find specified file)
Call Stack (most recent call first):
cmake/Utils.cmake:200 (dedent)
caffe2/CMakeLists.txt:145 (pycmd)
解決方案:
修改cmake/Utils.cmake檔案,這個問題估計再更新的caffe2就會沒有了。
參見網址:https://github.com/pytorch/pytorch/pull/6296/commits/88ae3f4c4feb50532b64b2f5d1110a7c2e81ceb6
3. 問題無法串連python27.lib
“X:\caffe2\build\ALL_BUILD.vcxproj”(預設目標) (1) ->“X:\caffe2\build\caffe2\caffe2_pybind11_state.vcxproj”(預設目標) (8) ->(Link 目標) -> LINK : fatal error LNK1104: cannot open “python27.lib” [X:\caffe2\build\caffe2\caffe2_pybind11_state.vcxproj]
解決方案:開啟Caffe2.sln,然後安裝圖中操作:
然後就可以通過VS編譯一下Caffe2,至此Caffe2編譯完成。
編譯完後將caffe2_pybind11_state.pyd拷貝都python的DLLs目錄例如:XXX
\Anaconda2\DLLs
4. python使用:
import caffe2。但是會報no module的錯。
>>> import caffe2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named caffe2
解決方案(1):
>>> import sys
>>> sys.path.append("X:/XXXX/caffe2/build")
>>> import caffe2
>>> import caffe2.python
解決方案(2):
參考網址:https://www.cnblogs.com/shanql/articles/5477483.html
windows下:找到python安裝環境中的site-packages檔案夾:
建立mypkpath.pth(註:必須以.pth為尾碼),然後在檔案中將X:/XXXX/caffe2/build寫入儲存即可。
這樣的做法目的應該是類似C、C++將標頭檔告訴python,運行時python再找對應的dll。
windows編譯caffe2遇到的問題