Linux(Ubuntu14.04)下安装Anaconda和Spyder
Linux(Ubuntu14.04)下安裝Anaconda是為了安裝python所需要的各種庫以及他們的環(huán)境配置。
Spyder是使用python的IDE
安裝python和pip
一般linux系統(tǒng)都自帶python,所以不需要安裝。如果沒有的,安裝起來也非常方便。安裝完成后,可用version查看版本
# python --versionpip是專門用于安裝python各種依賴庫的,所以我們這里安裝一下pip1.5.6
先用鏈接下載安裝包?https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz,然后解壓,里面有一個setup.py的文件,執(zhí)行這個文件就可以安裝pip了
# sudo python setup.py install有些電腦可能會提示 no moudle name setuptools 的錯誤,這是沒有安裝setuptools的原因。那就需要先安裝一下setuptools, 到https://pypi.python.org/packages/source/s/setuptools/setuptools-19.2.tar.gz?下載安裝包setuptools-19.2.tar.gz,然后解壓執(zhí)行
# sudo python setup.py install 利用anaconda來配置python環(huán)境如果你上面兩步已經(jīng)沒有問題了,那么這一步可以省略。
如果你想簡單一些,利用anaconda來配置python環(huán)境,那么直接從這一步開始,可以省略上面兩步。
先到https://www.continuum.io/downloads?下載anaconda, 現(xiàn)在的版本有python2.7版本和python3.5版本,下載好對應(yīng)版本、對應(yīng)系統(tǒng)的anaconda,它實際上是一個sh腳本文件,大約280M左右。我下載的是linux版的python 2.7版本。
下載成功后,在終端執(zhí)行(2.7版本):
# bash Anaconda2-2.4.1-Linux-x86_64.sh??在安裝的過程中,會問你安裝路徑,直接回車默認(rèn)就可以了。有個地方問你是否將anaconda安裝路徑加入到環(huán)境變量(.bashrc)中,這個一定要輸入no!!!!!!否則你的py-faster-rcnn就不能正常導(dǎo)入caffe了。若是不小心用了yes,則需要在最后使用sudo gedit ~/.bashrc 然后把最后一行的Anaconda路徑去掉,source ~/.bashrc就搞定啦!
安裝成功后,會有當(dāng)前用戶根目錄下生成一個anaconda2的文件夾,里面就是安裝好的內(nèi)容。
輸入conda list 就可以查詢,你現(xiàn)在安裝了哪些庫,常用的numpy, scipy名列其中。如果你還有什么包沒有安裝上,可以運(yùn)行
conda install *** ?來進(jìn)行安裝,
如果某個包版本不是最新的,運(yùn)行 conda update *** 就可以了。
?
編譯python接口
首先,將caffe根目錄下的python文件夾加入到環(huán)境變量
打開配置文件bashrc
# sudo vi ~/.bashrc ************************************************************************************* PS: 保存命令按ESC鍵 跳到命令模式,然后::w 保存文件但不退出vi :w file 將修改另外保存到file中,不退出vi :w! 強(qiáng)制保存,不推出vi :wq 保存文件并退出vi :wq! 強(qiáng)制保存文件,并退出vi q: 不保存文件,退出vi :q! 不保存文件,強(qiáng)制退出vi :e! 放棄所有修改,從上次保存文件開始再編輯*************************************************************************************在最后面加入
export PYTHONPATH=/home/leo/caffe/python:$PYTHONPATH注意?/home/leo/caffe/python 是我的路徑,這個地方每個人都不同,需要修改
保存退出,更新配置文件
# sudo ldconfig然后修改編譯配置文件Makefile.config. 我的配置是:
## 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 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_50,code=compute_50# 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 := $(HOME)/anaconda2 PYTHON_INCLUDE := $(ANACONDA_HOME)/include \$(ANACONDA_HOME)/include/python2.7 \$(ANACONDA_HOME)/lib/python2.7/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 LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib# 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# 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 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 ?= @修改完編譯配置文件后,最后進(jìn)行編譯:
# sudo make pycaffe編譯成功后,不能重復(fù)編譯,否則會提示 Nothing to be done for "pycaffe"的錯誤。
防止其它意外的錯誤,最好還編譯一下:
# sudo make test -j8 # sudo make runtest -j8也許你在編譯runtest的時候,會報這樣的錯誤:
.build_release/test/test_all.testbin: error while loading shared libraries: libhdf5.so.10: cannot open shared object file: No such file or directory
這是因為?libhdf5.so的版本問題,你可以進(jìn)入/usr/lib/x86_64-linux-gnu看一下,你的libhdf5.so.x中的那個x是多少,比如我的是libhdf5.so.7
?因此可以執(zhí)行下面幾行代碼解決:
# cd /usr/lib/x86_64-linux-gnu # sudo ln -s libhdf5.so.7 libhdf5.so.10 # sudo ln -s libhdf5_hl.so.7 libhdf5_hl.so.10 # sudo ldconfig最終查看python接口是否編譯成功:
進(jìn)入python環(huán)境,進(jìn)行import操作
# python >>> import caffe如果沒有提示錯誤,則編譯成功。
我出現(xiàn)的問題是ImportError: No module named google.protobuf.internal
解決方法:直接在終端中安裝protobuf,代碼:pip install protobuf
在github上https://github.com/spyder-ide/spyder下載軟件包
?
sudo pip install spyderconda install QtPyconda install Pylint
?
test code:
from skimage import ioimg=io.imread('d:/dog.jpg')io.imshow(img)
將其中的d:/dog.jpg 改成你的圖片位置
然后點擊上面工具欄里的綠色三角進(jìn)行運(yùn)行,最終顯示
如果右下角“ Ipython console" 能顯示出圖片,說明我們的運(yùn)行環(huán)境安裝成功。
我們可以選擇右上角的 ” variable explorer" 來查看圖片信息,如
我們可以把這個程序保存起來,注意python腳本文件的后綴名為py.
四、skimage包的子模塊
skimage包的全稱是scikit-image?SciKit (toolkit for?SciPy) ,它對scipy.ndimage進(jìn)行了擴(kuò)展,提供了更多的圖片處理功能。它是由python語言編寫的,由scipy 社區(qū)開發(fā)和維護(hù)。skimage包由許多的子模塊組成,各個子模塊提供不同的功能。主要子模塊列表如下:
| 子模塊名稱 | 主要實現(xiàn)功能 |
| io | 讀取、保存和顯示圖片或視頻 |
| data | 提供一些測試圖片和樣本數(shù)據(jù) |
| color | 顏色空間變換 |
| filters | 圖像增強(qiáng)、邊緣檢測、排序濾波器、自動閾值等 |
| draw | 操作于numpy數(shù)組上的基本圖形繪制,包括線條、矩形、圓和文本等 |
| transform | 幾何變換或其它變換,如旋轉(zhuǎn)、拉伸和拉東變換等 |
| morphology | 形態(tài)學(xué)操作,如開閉運(yùn)算、骨架提取等 |
| exposure | 圖片強(qiáng)度調(diào)整,如亮度調(diào)整、直方圖均衡等 |
| feature | 特征檢測與提取等 |
| measure | 圖像屬性的測量,如相似性或等高線等 |
| segmentation | 圖像分割 |
| restoration | 圖像恢復(fù) |
| util | 通用函數(shù) |
用到一些圖片處理的操作函數(shù)時,需要導(dǎo)入對應(yīng)的子模塊,如果需要導(dǎo)入多個子模塊,則用逗號隔開,如:
from skimage import io,data,color參考:http://www.cnblogs.com/denny402/p/5088399.html總結(jié)
以上是生活随笔為你收集整理的Linux(Ubuntu14.04)下安装Anaconda和Spyder的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 当我学完Python我学了些什么
- 下一篇: windows上安装Anaconda和p