Skip to content

Instantly share code, notes, and snippets.

@alexlee-gk
Created February 9, 2016 02:15
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save alexlee-gk/ba07524dc0d972be9eac to your computer and use it in GitHub Desktop.
Save alexlee-gk/ba07524dc0d972be9eac to your computer and use it in GitHub Desktop.
Install caffe with python 3.5 and pyenv

Install caffe with python 3.5 and pyenv

Tested on Ubuntu 14.04.

Setting up a new python environment using pyenv

Install desired version of python 3 (e.g. 3.5.1). Make sure to use the --enable-shared flag to generate python shared libraries, which will later be linked to.

env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.5.1

Go to a directory where we will do all the following operations. Set that directory to use the version of python that was just installed.

pyenv local 3.5.1

Get pip for the new installation of python.

wget https://bootstrap.pypa.io/get-pip.py; python get-pip.py; rm get-pip.py

Installing boost

We need to build boost from source since the one from the package manager doesn't support python 3.5 (as of now). Download one of the recent versions of boost from here (I used boost 1.60.0).

If you are using CUDA, you might run into a compiler error involving nvcc, in which case this patch might solve it.

Build and install boost, telling it to use the python from pyenv.

./bootstrap.sh --with-python=~/.pyenv/versions/3.5.1/bin/python3.5
./b2
# installs to /usr/local/ by default
sudo ./b2 install

Installing caffe

The instructions are mostly the same as the official installation instructions except for a few modifications specified below.

First, install the usual system dependencies as described in here.

Then, install the usual python dependecies using pip, but first update the requirements.txt file to use protobuf 3.0 alpha. Replace the protobuf line with this one:

pip install protobuf==3.0.0-alpha-3

Install all the requirements as usual:

for req in $(cat requirements.txt); do pip install $req; done

When using cmake, make sure to specify the python from pyenv that you want to use, e.g.

cmake -DPYTHON_INCLUDE_DIR=~/.pyenv/versions/3.5.1/include/python3.5m -DPYTHON_INCLUDE_DIR2=~/.pyenv/versions/3.5.1/include/python3.5m -DPYTHON_LIBRARY=~/.pyenv/versions/3.5.1/lib/libpython3.so -Dpython_version=3 ../caffe
@arc279
Copy link

arc279 commented Jan 16, 2017

You can also use python-config command, in pyenv.
e.g. export CPLUS_INCLUDE_PATH="$CPLUS_INCLUDE_PATH:$(python-config --prefix)/include"

@vaibhav0195
Copy link

hi using your way i got an error saying :

CMake Error at cmake/Dependencies.cmake:148 (STRING):
string sub-command REGEX, mode REPLACE needs at least 6 arguments total to
command.
Call Stack (most recent call first):
CMakeLists.txt:46 (include)

can you walk me through this ?
thanks

@cuixing158
Copy link

how to do on Windows compile?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment