1. 安装编译
# Clone Caffe2's source code from Github repository
git clone https://github.com/pytorch/pytorch.git && cd pytorch
# Checkout the tag v0.4.1
git checkout v0.4.1
# Clone third party dependencies
git submodule update --init
# Create a directory to put Caffe2's build files in
mkdir build && cd build
# Configure Caffe2's build
# This looks for packages on your machine and figures out which functionality
# to include in the Caffe2 installation. The output of this command is very
# useful in debugging.
# To cmake with python3.6, use cmake with DPYTHON_EXECUTABLE DPYTHON_LIBRARY DPYTHON_INCLUDE_DIR.
# I use virtual enviroment here which is very useful for different tasks.
cmake .. \
-DPYTHON_EXECUTABLE=/usr/local/bin/python3.6m \
-DPYTHON_LIBRARY=/Users/yuhua.cheng/Opt/myenv/lib/python3.6/config-3.6m-darwin/libpython3.6.a \
-DPYTHON_INCLUDE_DIR=/Users/yuhua.cheng/Opt/myenv/include/python3.6m
# Compile, link, and install Caffe2 (-j8 is optional)
sudo make install -j8
2. 配置环境变量
vi ~/.bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/PATH/TO/pytorch/build/lib
export PYTHONPATH=$PYTHONPATH:/PATH/TO/pytorch/build
保存之后source ~/.bashrc
测试:
In [1]: import caffe2
In [2]: from caffe2.python import core
WARNING:root:This caffe2 python run does not have GPU support. Will run in CPU only mode.
这样安装的包好像不能打开lmdb文件,真是坑多,心累。
网友评论