我是靠谱客的博主 着急电话,这篇文章主要介绍虚拟机中ubuntu17.04+python3.6+anaconda3配置caffe(CPU),现在分享给大家,希望可以做个参考。

新手第一次配置caffe,加上课业繁重每天几乎只有中午饭后睡前和晚上下课以后有时间搞一点点,最后找了个周六自己花了一天时间安好,希望能记录下来。

首先是安装ubuntu17.04虚拟机,这个不必多说。官网上我看到了caffe对ubuntu17.04的安装教程,可能是因为我还没参透吧,毕竟ubuntu接触了时间不长,最后还是找了16.04和14.04的教程最终安装完成。

下面开始caffe安装啦。

1.安装python3.6

从官网上下载,我的是3.6.3。附官网链接点击打开链接 下载文件Python3.6.3.tar.xz

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
tar xJf Python-3.6.1.tar.xz cd Python-3.6.1 ./configure make /*这步如果需要sudo,请使用sudo -H命令,即sudo -H make install,避免pip等模块安装失败。 错误示例(pip安装失败):The directory '/home/ls/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. */ make install
作者:Shawpo 链接:http://www.jianshu.com/p/2fd6383ec010 來源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
tar xJf Python-3.6.1.tar.xz cd Python-3.6.1 ./configure make /*这步如果需要sudo,请使用sudo -H命令,即sudo -H make install,避免pip等模块安装失败。 错误示例(pip安装失败):The directory '/home/ls/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. */ make install
作者:Shawpo 链接:http://www.jianshu.com/p/2fd6383ec010 來源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
复制代码
1
2
3
4
5
6
7
8
tar xJf Python-3.6.1.tar.xz cd Python-3.6.1 ./configure --enable-shared //解决共享库libpython3.6m.so.1.0问题,后期遇到重新编译会很麻烦 make make install cp libpython3.6m.so.1.0 /usr/lib

*****************************************************************************************

若遇到错误提示发现使用zlib库出错

复制代码
1
sudo apt-get install libbz2-dev libgdbm-dev liblzma-dev libreadline-dev libsqlite3-dev libssl-dev tcl-dev tk-dev dpkg-dev

*****************************************************************************************

2.配置anaconda3

官网下载点击打开链接

下载完之后是后缀.sh的文件,终端输入

复制代码
1
bash Anaconda3-5.0.0.1-Linux-x86_64.sh

3.切换默认python版本

终端键入python查看版本,如果默认不是python3

复制代码
1
2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

如果要切换到Python2,执行:

sudo update-alternatives --config python


正式开始安装caffe:

4.安装依赖库

复制代码
1
2
3
4
5
6
7
sudo apt-get install libprotobuf-dev sudo apt-get install libleveldb-dev sudo apt-get install libsnappy-dev sudo apt-get install libopencv-dev sudo apt-get install libhdf5-serial-dev sudo apt-get install protobuf-compiler sudo apt-get install --no-install-recommends libboost-all-dev

接下来是BLAS:

复制代码
1
2
sudo apt-get install libatlas-base-dev

建立pycaffe接口:

复制代码
1
sudo apt-get install python-dev

以及一些依赖库:

复制代码
1
2
3
4
sudo apt-get install libgflags-dev sudo apt-get install libgoogle-glog-dev sudo apt-get install liblmdb-dev


5.下载caffe源码:

首先安装git

复制代码
1
sudo apt-get install git

然后下载caffe源码:

复制代码
1
git clone https://github.com/BVLC/caffe.git

之后:

复制代码
1
2
3
4
cd caffe/python sudo apt-get install python-pip  for req in $(cat requirements.txt); do pip install $req; done

6.编译caffe源码:

复制代码
1
2
cp Makefile.config.example Makefile.config
文本编辑器打开Makefile.config对文件做相应的修改:共四处


复制代码
1
2
3
# CPU-only switch (uncomment to build without GPU support). CPU_ONLY := 1

这里取消注释


复制代码
1
2
3
# Uncomment to support layers written in Python (will link against Python libs) WITH_PYTHON_LAYER := 1
这里取消注释

复制代码
1
2
3
4
# Whatever else you find you need goes here. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
这里修改为如图

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# NOTE: this is required only if you will compile the python interface. # We need to be able to find Python.h and numpy/arrayobject.h. # PYTHON_INCLUDE := /usr/include/python2.7 # /usr/lib/python2.7/dist-packages/numpy/core/include # Anaconda Python distribution is quite popular. Include path: # Verify anaconda location, sometimes it's in root. ANACONDA_HOME := $(HOME)/anaconda3 # PYTHON_INCLUDE := $(ANACONDA_HOME)/include # $(ANACONDA_HOME)/include/python2.7 # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include # Uncomment to use Python 3 (default is Python 2) PYTHON_LIBRARIES := boost_python3 python3.6m PYTHON_INCLUDE := /usr/include/python3.6m /usr/lib/python3.6/dist-packages/numpy/core/include

默认为python2的路径,把python2的路径注释掉,把python3的路径取消注释,注意anaconda的路径需要修改。


7.开始编译:

复制代码
1
2
3
4
make pycaffe make all make test make runtest
如果有错误,先make clean再重新编译。

*****************************************************************************************

错误信息没有pyconfig.h文件

复制代码
1
export CPLUS_INCLUDE_PATH=/usr/include/python2.7
注意每次clean之后都要重来一次


错误信息fatal error: numpy/arrayobject.h没有那个文件或目录:

复制代码
1
sudo apt-get install python-numpy

错误信息/usr/bin/ld:cannot find -lboost_python3

复制代码
1
2
3
复制代码
cd /usr/lib/x86_64-linux-gnu/
sudo ln -s libboost_python-py35.so libboost_python3.so

错误信息dpkg:处理软件包xxx(--config)时出错:

复制代码
1
2
3
4
5
6
sudo mv /var/lib/dpkg/info /var/lib/dpkg/info_old

sudo mkdir /var/lib/dpkg/info

sudo apt-get update

sudo apt-get -f install

sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info_old

sudo rm -rf /var/lib/dpkg/info

sudo mv /var/lib/dpkg/info_old /var/lib/dpkg/info  



*****************************************************************************************

最后

复制代码
1
2
python import caffe


结束。


喝一杯咖啡真难啊。




复制代码
1
2

最后

以上就是着急电话最近收集整理的关于虚拟机中ubuntu17.04+python3.6+anaconda3配置caffe(CPU)的全部内容,更多相关虚拟机中ubuntu17内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(74)

评论列表共有 0 条评论

立即
投稿
返回
顶部