您的位置:首页 > 移动开发

安装Caffe的Python wrapper时出现问题的解决方法

2014-07-24 09:17 856 查看
Caffe的安装可以参考我之前的文章caffe安装指南(Ubuntu13.04 x86)

这篇文章是之前文章中前置软件安装中python的拓展,如果已经按照之前的安装好了,可以先在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 install cython
(python缺少的库都可以用pip install安装)

这里出现了第一个问题:

File "/usr/local/lib/python2.7/dist-packages/setuptools/command/install_egg_info.py",
line 5, in

from setuptools.archive_util import unpack_archive


File "/usr/local/lib/python2.7/dist-packages/setuptools/archive_util.py", line 15, in
from pkg_resources import 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 python setup.py install
即可安装。

安装完后,上述问题顺利解决,遇到第二个错误提示:

File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 594, in resolve  

raise DistributionNotFound(req)

pkg_resources.DistributionNotFound: distribute

解决方法是:安装distribute包

$ wget http://python-distribute.org/distribute_setup.py $ python distribute_setup.py
(http://stackoverflow.com/questions/19400370/easy-install-and-pip-broke-pkg-resources-distributionnotfound-distribute-0-6)

2.安装scikit-image

$sudo pip install scikit-image
提示的错误是:

ImportError: You need `six` version 1.3 or later.

尝试了

$sudo pip install six


发现已经安装了,那么问题就是版本没到1.3以上

解决方法:

$sudo pip install six==1.3


3.安装scipy

$sudo pip install scipy


错误提示:

building 'dfftpack' library

error: library dfftpack has Fortran sources but no Fortran compiler found
也就是没有安装gfortran编译器

解决方法:

$sudo apt-get install 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
即可安装,这三个包有前置关系,安装时注意看提示即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Caffe Python