[PYTHON] How to install caffe on OS X with macports

Install Caffe on AirPort with macports. There is no GPU, so only CPU mode.

By the way, if you use anaconda and macports at the same time, you cannot use pycaffe due to library conflict. .. .. See Install Caffe on OSX 10.11 with macports + anaconda. Here, macports alone is used.

macports

Package installation


sudo port install gcc5
sudo port install atlas +gcc5
sudo port install OpenBLAS +gcc5 +lapack
sudo port install py27-altgraph py27-appnope py27-backports py27-backports-ssl_match_hostname py27-bottleneck py27-cairo py27-certifi py27-config py27-cython py27-dateutil py27-decorator py27-functools32 py27-gflags py27-gnureadline py27-h5py py27-ipykernel py27-ipyparallel py27-ipython py27-ipython_genutils py27-ipywidgets py27-jinja2 py27-jsonschema py27-jupyter_client py27-jupyter_core py27-leveldb py27-macholib py27-markupsafe py27-matplotlib py27-mistune py27-modulegraph py27-nbconvert py27-nbformat py27-networkx py27-nose py27-notebook py27-numexpr py27-numpy py27-pandas py27-pandas py27-parsing py27-path py27-pexpect py27-pickleshare py27-Pillow py27-pkgconfig py27-powerline py27-protobuf py27-ptyprocess py27-py2app py27-pygments py27-pyobjc py27-pyobjc-cocoa py27-scientific py27-scikit-image py27-scikit-learn py27-scipy py27-setuptools py27-setuptools_scm py27-simplegeneric py27-six py27-tables py27-terminado py27-tkinter py27-tornado py27-traitlets py27-tz py27-vcversioner py27-yaml py27-zmq
sudo port install boost +python27
sudo port install opencv +python27 +eigen +tbb +vtk +contrib
sudo port install protobuf-c protobuf-cpp gflags google-glog hdf5 leveldb snappy lmdb 

Compile caffe itself with clang ++ (If you do it with g ++, it says you can't find libraries such as protbuf and opencv, maybe because you're compiling with clang?)

port select

Let's use port select


sudo port select --set python python27
sudo port select --set python2 python27
sudo port select --set ipython2 py27-ipython
sudo port select --set nosetests nosetests27

Below, if you use caffe with python, use 2.7. (If it is a recent version, it seems that 3.3 or later is OK. It is described on the official web. I have not tried it)

caffe

download caffe


git clone https://github.com/BVLC/caffe.git
cd caffe
cp Makefile.config.example Makefile.config

Rewrite Makefile.config here.

Makefile.config changes


--- Makefile.config.example	2016-07-07 15:42:18.000000000 +0900
+++ Makefile.config	2016-07-07 15:46:08.000000000 +0900
@@ -5,7 +5,7 @@
 # USE_CUDNN := 1
 
 # CPU-only switch (uncomment to build without GPU support).
-# CPU_ONLY := 1
+CPU_ONLY := 1
 
 # uncomment to disable IO dependencies and corresponding data layers
 # USE_OPENCV := 0
@@ -43,7 +43,7 @@
 # atlas for ATLAS (default)
 # mkl for MKL
 # open for OpenBlas
-BLAS := atlas
+BLAS := open
 # Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
 # Leave commented to accept the defaults for your choice of BLAS
 # (which should work)!
@@ -61,14 +61,15 @@
 
 # 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
+#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)/anaconda
-# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
-		# $(ANACONDA_HOME)/include/python2.7 \
-		# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \
+ANACONDA_HOME := /opt/local/Library/Frameworks/Python.framework/Versions/2.7/
+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.5m
@@ -76,19 +77,19 @@
 #                 /usr/lib/python3.5/dist-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
+# 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
+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
+INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /opt/local/include
+LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /opt/local/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
@@ -96,7 +97,7 @@
 
 # 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
+USE_PKG_CONFIG := 1
 
 # N.B. both build and distribute dirs are cleared on `make clean`
 BUILD_DIR := build
@@ -109,4 +110,4 @@
 TEST_GPUID := 0
 
 # enable pretty build (comment to see full commands)
-Q ?= @
+#Q ?= @

Rewrite Mekfile. --Add -mt to the boost library.

Makefile changes


--- Makefile.org	2016-07-07 15:42:18.000000000 +0900
+++ Makefile	2016-07-07 15:58:24.000000000 +0900
@@ -178,7 +178,7 @@
 	LIBRARIES := cudart cublas curand
 endif
 
-LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
+LIBRARIES += glog gflags protobuf boost_system-mt boost_filesystem-mt m hdf5_hl hdf5
 
 # handle IO dependencies
 USE_LEVELDB ?= 1
@@ -199,7 +199,7 @@
 	endif
 		
 endif
-PYTHON_LIBRARIES ?= boost_python python2.7
+PYTHON_LIBRARIES ?= boost_python-mt python2.7
 WARNINGS := -Wall -Wno-sign-compare
 
 ##############################

Then make.

Build


make all pycaffe

test


make all test runtest pytest

Installation

How to install locally.

python


make distribute

mkdir -p $HOME/local/usr/local/lib/python2.7/site-packages/

cp -rv distribute/include $HOME/local/usr/local/
cp -rv distribute/lib $HOME/local/usr/local/
cp -rv distribute/python/caffe $HOME/local/usr/local/lib/python2.7/site-packages/

If you use pycaffe

.bash_Settings to write in profile etc.


# caffe
export LD_LIBRARY_PATH=$HOME/local/usr/local/lib/:$LD_LIBRARY_PATH
export PYTHONPATH=$HOME/local/usr/local/lib/python2.7/site-packages/:$PYTHONPATH

with this python2.7 Or jupyter-notebook-2.7 You can use pycaffe with.

import


import caffe

If no error occurs, it's OK.

Recommended Posts

How to install caffe on OS X with macports
How to install Theano on Mac OS X with homebrew
How to install OpenGM on OSX with macports
How to install Theano on Mac OS X 10.10 (using pyenv, anaconda)
Install PyQt5 with homebrew on Mac OS X Marvericks (10.9.2)
How to install mysql-connector-python on mac
Install Sphinx on Mac OS X
How to install python-pip with ubuntu20.04LTS
How to install graph-tool on macOS
How to install VMware-Tools on Linux
How to install pycrypto on Windows
How to install OpenCV on Mac
How to install PyPy on CentOS
How to install TensorFlow on CentOS 7
Install mitmproxy on Mac OS X
Install pyStruct on MacOSX10.11 with macports
How to install mysql-connector with pip3
How to install Maven on CentOS
How to install Go on Ubuntu
How to install music 21 on windows
How to install Anaconda with pyenv
Install pgmagick on Mac OS X 10.9
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
How to install aws-session-manager-plugin on Manajro Linux
Install matplotlib on OS X El Capitan
[Kivy] How to install Kivy on Windows [Python]
How to install pandas on EC2 (How to deal with MemoryError and PermissionError)
How to erase Python 2.x on Mac.
How to install packages on Alpine Linux
How to install Anisble on Amazon Linux 2
How to install richzhang / colorization on Windows 10
How to install Apache (httpd) on CentOS7
How to install php7.4 on Linux (Ubuntu)
How to install Eclipse GlassFish 5.1.0 on CentOS 7
Install lp_solve on Mac OS X and call it with python.
How to install Apache (httpd) on CentOS8
How to install zsh (with .zshrc customization)
How to install NumPy on Raspberry Pi
How to install cx_Oracle on macOS Sierra
How to install python3 with docker centos
How to install Deep Learning framework Caffe on Mac in CPU mode
Install NumPy, SciPy, Matplotlib with Homebrew on OS X (as of November 2015)
[2020 version] How to install Python3 on AWS EC2
Strategy on how to monetize with Python Java
How to install OpenCV on Jetson Nano Python
How to quickly install h5py on Windows 10 [Unofficial]
Install shogun with python modular (OS X Yosemite)
How to install Camunda Modeler on Manjaro Linux
[Python] How to install OpenCV on Anaconda [Windows]
How to install / verify graphviz on anaconda / windows10
How to install Python
How to install pip
How to install archlinux
How to install python
How to install BayesOpt
Install aws-cli on MacPorts
How to install Nbextensions
Install Caffe on Mac
How to install Prover9
Preparing to use aws cli on Mac OS X
How to install Linux on a 32bit UEFI PC