您的位置:首页 > Web前端

Ubuntu16.04安装过程

2018-03-03 09:05 393 查看
之前一直在博客园发表文章。每次编写都要借助第三方的markdown编辑器,这一点的确没有CSDN方便。所以以后还是在CSDN吧。之前的博客也不准备转移了。今天就作为我的第一篇CSDN博客。

之前的笔记本年久失修,沦为超大MP4。于是从家里拿了一个二手货,勉强能用。今天给电脑装了系统,考虑到平时的工作娱乐,觉得使用Ubuntu更方便一点,就没有装双系统,只装了Ubuntu16.04。这里对装机记录做一些笔记,重点是我的常用工具,方便以后再装系统时不至于焦头烂额。

1.BIOS设置启动盘失败

可能时这台电脑时间也久了吧,主板电池没电了。我在设置系统盘启动的时候,每次选择从优盘启动,按下F10保存退出,再启动又是从原装Windows系统进入。一开始在Windows上研究,最后才明白是BIOS的问题。解决方法很简单,首先是保存修改但不退出(大部分BIOS应该有这个选项),然后用ESC直接退出,也就是不掉电启动。这样设置就生效了。

2.网络连接失败

网络不能链接应该是Ubuntu安装常见错误。我的情况是无线没有任何热点选项,插有线也链接不上。最后参考了一篇ubuntu16.04拨号上网及无线驱动安装博客成功解决。简要步骤就是先设置PPPOE有线上网,然后在附加驱动中添加网卡驱动。其实一开始完全没有必要像其他人说的那样配置一堆文件。

3.换源

我用的源是参考这篇博客——2017年最新版本apt-get安装源替换 阿里云源。不过有一点要注意,不要删除(rm)原来的sources.list,而是应该备份(cp)。

4.安装搜狗拼音,chrome,cmake,git,VScode

安装搜狗拼音总是会出问题,deb包没办法直接安装。解决方案是ubuntu安装搜狗拼音。之后以此安装chrome,cmake,git,VScode。chrome和VScode采用deb以
dpkg -i <>.deb
方式安装。cmake和git采用
sudo apt-get install <>
的方式安装。git安装完成之后要配置与github的SSH链接,配置方法Linux中git的使用。VScode一般我会选择C/C++,C++ Intellisense,Python,vscode-icons这四个插件。

5.安装anaconda

虽然ubuntu已经安装了Python2和3,但是建议还是装一个anaconda。否则后面执行caffe的Python接口时发现总是少几个库,就很麻烦了。安装方法是linux下安装anaconda

安装之后一定要用命令
conda install -c https://conda.anaconda.org/anaconda protobuf
安装protobuf,这个对caffe的Python接口很重要。

6.caffe的GPU版本安装

安装过程参考了ubuntu16.04安装caffe的GPU版本l。这次重新安装,又踩了几个坑。首先是NVIDIA驱动不能使用系统设置->附加驱动中的NVIDIA显卡驱动,后面安装cuda会提示没有驱动,不能执行。所以还是要去官网上下载驱动,安装方式还是要采用禁止nouveau,重启进入tty1终端,删除与NVIDIA启动相关项,停止X Windows服务,使用命令
sudo ./NVIDIA-Linux-x86_64-375.20.run –no-x-check –no-nouveau-check –no-opengl-files
才可以,否则会循环进入启动界面。

sudo apt-get remove –purge nvidia*
sudo service lightdm stop
sudo ./NVIDIA-Linux-x86_64-375.20.run –no-x-check –no-nouveau-check –no-opengl-files
sudo service lightdm start


在进入驱动安装中出现DKMS设置,虽然不清楚是什么,但一定要选择是,否则会失败。

另外本次也尝试先安装CUDA,再安装驱动,证明是可行的。

这次安装caffe时设置Python接口。实际上Ubuntu已经安装了Python2和3,不需要自己再安装一个。但是对caffe还需要一些包。所以还是安装anaconda,而且配置文件也留有相关的接口。

下面是配置文件

## Refer to http://caffe.berkeleyvision.org/installation.html # Contributions simplifying and improving our build system are welcome!

# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1

# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1

# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
#   You should not set this flag if you will be reading LMDBs with any
#   possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1

# Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3

# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
CUDA_ARCH := #-gencode arch=compute_20,code=sm_20 \
#-gencode arch=compute_20,code=sm_21 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode
4000
arch=compute_61,code=compute_61

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas

# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

# 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 := /usr/local/anaconda3
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python3.6m \
$(ANACONDA_HOME)/lib/python3.6/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)
PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
#/home/sgdd/.local/lib/python3.5/site-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
# PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1

# 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 /usr/lib/x86_64-linux-gnu/hdf5/serial

# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib

# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171 # DEBUG := 1

# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0

# enable pretty build (comment to see full commands)
Q ?= @


这个配置文件肯定不会适用于任何情况,对于其他的环境要对比着修改。

如果出现
nvcc fatal : Unsupported gpu architecture 'compute_20'
应该是文件中cuda的配置出错,把compute_20和compute_21所在行注释掉就可以了。

如果出现
Cannot build caffe with anaconda. Error: while loading shared libraries: libhdf5_hl.so.10
,是找不到anaconda的lib目录,要增加环境变量
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:{anaconda_dir}/lib


如果anaconda是Python3的话,这一行取消注释

PYTHON_LIBRARIES := boost_python3 python3.5m


否则会报错:/python/caffe/_caffe.so: undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE

我在安装中遇到了这些问题。这里推荐一个博客,对问题的记录很多,都是在运行caffe的过程中出现的。ubuntu16.04下,安装caffe+cuda8.0+cudnn5.1(附各种错误解决)

我之前的博客介绍了另一中编译caffe的方法,现在认识到这样做是错误的。因为cmake根本没有参考makefile.config的信息。能运行成功应该只是巧合,表示cmakelist.txt中的配置和你的电脑没有矛盾。正确的编译命令是

make all -j4
make test
make runtest
make pycaffe
make pytest


命令中j4是指打开4个线程运行,可以根据自己电脑的核数自行决定。

如果你没有安装anaconda,运行中可能会因为没有安装protobuf出现各种错误,特别在pytest,总是缺少某个module。而用anaconda就可以应用命令
conda install -c https://conda.anaconda.org/anaconda protobuf
一键安装。

7.安装ROS

教程——Ubuntu install of ROS Kinetic,注意修改库的时候要用国内的镜像。

8.设置开机启动

有一些命令如果每次都要输入,建议做一个开机启动项。教程——Ubuntu下设置开机后自动运行命令
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Ubuntu16.04 caffe GPU BIOS