在caffe-master目錄下執行
$make pycaffe
如果提示不能make pycaffe,可以先執行
$make clean
(以上步驟也可以放在最後進行)
安裝其他的庫需要的只是執
$ sudo pip install-r /path/to/caffe/python/requirements.txt
其中包括
Cython>=0.19.2
h5py>=2.2.0
ipython>=1.1.0
leveldb>=0.191
matplotlib>=1.3.1
networkx>=1.8.1
nose>=1.3.0
numpy>=1.7.1
pandas>=0.12.0
protobuf>=2.5.0
python-gflags>=2.0
scikit-image>=0.9.3
scikit-learn>=0.14.1
scipy>=0.13.2
但是我在安裝中碰到了一些問題,導致無法正確安裝,因此,我是在後續的程序運行中遇到了需要的庫再獨立安裝,主要問題出現在Cython,scikit-image和scipy上
1.Cython需要在scikit-image之前安裝
$ sudo pip installcython
(python缺少的庫都可以用pip install安裝)
這裏出現了第一個問題:
File"/usr/local/lib/python2.7/dist-packages/setuptools/command/install_egg_info.py",line 5, in
fromsetuptools.archive_util import unpack_archive
File"/usr/local/lib/python2.7/dist-packages/setuptools/archive_util.py",line 15, in
from pkg_resourcesimport ensure_directory, ContextualZipFile
ImportError:cannot import name ContextualZipFile
經過了千辛萬苦翻牆搜索後得到了解決方法
這個問題實際上是處在setuptools上,從上面的traceback中也可以發現,一位友好的國際友人提供了修改過的setuptools安裝包 setuptools-5.4.1.zip
(https://bitbucket.org/pypa/setuptools/issue/234/setuptools-import-error-of-class)
解壓之後在目錄中執行
$ sudo pythonsetup.py install
即可安裝。
安裝完後,上述問題順利解決,遇到第二個錯誤提示:
File"/usr/lib/python2.7/dist-packages/pkg_resources.py", line 594, in resolve
raiseDistributionNotFound(req)
pkg_resources.DistributionNotFound:distribute
解決方法是:安裝distribute包
$ wgethttp://python-distribute.org/distribute_setup.py
$ pythondistribute_setup.py
(http://stackoverflow.com/questions/19400370/easy-install-and-pip-broke-pkg-resources-distributionnotfound-distribute-0-6)
2.安裝scikit-image
$sudo pip installscikit-image
提示的錯誤是:
ImportError: Youneed `six` version 1.3 or later.
嘗試了
$sudo pip installsix
發現已經安裝了,那麼問題就是版本沒到1.3以上
解決方法:
$sudo pip installsix==1.3
3.安裝scipy
$sudo pip installscipy
錯誤提示: building 'dfftpack' library
error: librarydfftpack has Fortran sources but no Fortran compiler found
也就是沒有安裝gfortran編譯器
解決方法:
$sudo apt-getinstall gfortran
一般來說這裏是可以直接解決的,但是由於網絡原因,提示404 not found,在嘗試了多種方法後都沒有解決。
觀察運行過程,發現需要安裝的包括:
gfortran-4.7_4.7.3-1ubuntu1_amd64.deb
gfortran_4.7.3-1ubuntu10_amd64.deb
libgfortran-4.7-dev_4.7.3-1ubuntu1_amd64.deb
從Google上搜索可以很容易找到下載,下載後
$sudo dpkg -i*.deb
即可安裝,這三個包有前置關係,安裝時注意看提示即可。