在Mac上安装mxnet+cuda+opencv3+python3

mxnet在mac上的编译,坑非常多,比如config.mk中的配置,必须注意行尾无空格,否则就会找不到库。现将步骤总结如下:

1. 安装brew并添加相关源

$/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$brew tap homebrew/science

2. 下载并安装Xcode Command Line Tools

$xcode-select --install

3. 安装CUDA

在nvidia 官网选择对应的版本下载并安装
https://developer.nvidia.com/cuda-downloads

设置环境变量,编辑.bash_profile文件:

vi ~/.bash_profile

在开头添加CUDA的环境变量:

export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$CUDA_HOME/lib"
export PATH="$CUDA_HOME/bin:$PATH"

4. 安装Python3

$brew install python3

5. 通过brew安装opencv3和openblas

用brew编译opencv3

$brew install opencv3 --with-ippicv --with-contrib --with-python3 --with-cuda --c++11
$brew link --overwrite --force opencv3 

用brew编译安装openblas

brew install openblas
brew link openblas

6. 安装mxnet

$git clone --recursive https://github.com/dmlc/mxnet
$cd mxnet
$cp make/osx.mk config.mk

用命令行修改 config.mk配置文件,避免行尾空格造成编译失败,输入:

echo "USE_CUDA = 1"  >> ./config.mk
echo "USE_CUDA_PATH = /usr/local/cuda" >> ./config.mk
echo "USE_BLAS = openblas" >> ./config.mk 
echo "ADD_CFLAGS += -I/usr/local/opt/openblas/include" >> ./config.mk 
echo "ADD_LDFLAGS += -L/usr/local/opt/openblas/lib" >> ./config.mk

7. 安装Python库

一路顺利的话,进入源码目录后的python目录,安装相应的python库:

cd python
sudo python3 setup.py install

小试一下:

$ python3
Python 3.5.2 (default, Dec 23 2016, 10:27:01) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mxnet
>>> 

如果没有错误的话,就表示已经安装成功了。

你可能感兴趣的:(在Mac上安装mxnet+cuda+opencv3+python3)